Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode, SFML error dyld: Library not loaded

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

like image 719
Mulperi Avatar asked Jan 03 '23 08:01

Mulperi


1 Answers

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.

like image 129
Mulperi Avatar answered Jan 05 '23 16:01

Mulperi