Xcode, SFML error dyld: Library not loaded
Asked Answered
W

4

6

I am trying to start a basic C++ project with link to SFML library. I have unzipped the SFML library to folder /Users/mulperi/cpplib/sfml and I have added that to Include Search Path and Library Search Path.

My code is simple, I followed a tutorial on Youtube (also tried different ready-made codes):

#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "First SML Window");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type) {
                case sf::Event::Closed:
                    window.close();
                    break;
                default:
                    break;
            }
        }
        window.clear();
        window.display();
    }
    return 0;
}

The build succeeds so the paths should be fine. I don't get the window, instead I have these outputs:

Thread 1:

dyld`__abort_with_payload:
    0x10003b1e0 <+0>:  movl   $0x2000209, %eax          ; imm = 0x2000209 
    0x10003b1e5 <+5>:  movq   %rcx, %r10
    0x10003b1e8 <+8>:  syscall 
->  0x10003b1ea <+10>: jae    0x10003b1f4               ; <+20>
    0x10003b1ec <+12>: movq   %rax, %rdi
    0x10003b1ef <+15>: jmp    0x10003aa48               ; cerror_nocancel
    0x10003b1f4 <+20>: retq   
    0x10003b1f5 <+21>: nop    
    0x10003b1f6 <+22>: nop    
    0x10003b1f7 <+23>: nop    

Output:

dyld: Library not loaded: @rpath/libsfml-system.2.5.dylib
  Referenced from: /Users/mulperi/Library/Developer/Xcode/DerivedData/sfml_1-cgodahbmxiufqnhhglbsyfuzvdvz/Build/Products/Debug/sfml_1
  Reason: image not found
(lldb) 

I am using Xcode 9.3.1 on High Sierra 10.13.4

Update: I also tried moving the SFML folder inside the project folder and even tried splitting up include,libs,frameworks,extlibs tu /usr/local like in the SFML tutorial but I always get the same output.

Here are pics of my settings Folder structure

Header search path

Library search path

Added frameworks too

The output

Wilt answered 28/5, 2018 at 19:4 Comment(0)
W
9

Ok I got it working after reading the getting started tutorial carefully again. On Mac, they recommend using the Framework files, so what I did was:

  1. Copy contents of SFML/Frameworks and SFML/extlibs to /Library/Frameworks
  2. Xcode project Build phases -> Link Binary with Libraries -> Add every SFML framework from the /Library/Frameworks folder (no need to add the extlib frameworks)

Note: No need to add Include Search Paths or Library Search Paths with this method.

Wilt answered 2/6, 2018 at 11:37 Comment(4)
Exactly what i needed. Thanks!Subsellium
Still not working here macOS 10.15.4, Xcode Version 11.4.1 (11E503a). Xcode is complaining about the signature of the files on framework and stops the compilation processCanoewood
@EduardoPereira You need to go to Mac's System Preferences, Security, and from there individually Admit permission for each framework one by one.Wilt
In my case, on top of the other things mentioned, I had to go Signing & Capabilities-> Hardened Runtime-> check Disable Library ValidationSpelunker
F
1

On Catalina the accepted solution does not seem to work anymore due to errors like:

sfml-audio.framework cannot be opened because the developer cannot be verified

Using homebrew solved it for me:

  • brew install sfml. Then on Xcode link the libraries installed by homebre by:
  • Navigating to the section 'Link Binaries With Libraries' on Xcode, drag and drop the sfml libraries from /usr/local/Cellar/sfml/x.x.x/lib directory

  • Click build and run. Project should now build and run successfully

Footy answered 15/2, 2020 at 23:19 Comment(1)
I did the exactly the same, but have had source problem yet..Rascon
N
1

I tried with the next steps in MacOS Catalina 10.15.4 (in 2020):

for use SFML in Xcode, try this:

--> 1. Install sfml dependency with: $ brew install sfml

--> 2. Go to Xcode project and add the following:(Very Important)

in "Header Search Paths" add "/usr/local/Cellar/sfml/2.5.1/include"

in "Library Search aths" add "/usr/local/Cellar/sfml/2.5.1/lib

2.5.1 is the sfml version, try with your current version.

--> 3. Go to "Build Phases / Link Binary with Libraries" section and add all "dylib" files:

  • '''-network.'''.dylib.
  • '''-window.'''.dylib.
  • '''-audio.'''.dylib.
  • '''-system.'''.dylib.
  • '''-graphics.'''.dylib.

--> 4. Finally, run your project.

Verify that all includes have been correctly added at top of file program and the namespace is correctly placed like:

#include <SFML/Graphics.hpp>

#include <iostream>

using namespace sf;

Nevsa answered 1/5, 2020 at 3:39 Comment(1)
I did the same steps, but have the source problem.. Program compiled and linked, but have SIGABRT and output "dyld: Library not loaded: @rpath/libsfml-system.2.5.dylib"Rascon
C
0

I tried the following on MacOS Ventura 13.6 (2023):

  1. After following the previous steps, installing sfml with homebrew | adding the paths to the Header/Library Search Paths | adding ".dylib" files to Build Phases / Link Binary with Libraries
  2. Under Build Settings/Signing set the option Enable Hardened Runtime: No
  3. Click build and run.

If the problem persists try changing other values under the Build Settings / Signing list

Apple | Hardened Runtime

Cocksure answered 27/12, 2023 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.