Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problems linking to the libraries for VS code on a Mac [SOLVED]  (Read 4304 times)

0 Members and 1 Guest are viewing this topic.

YaBoi

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hi there, I am new to C++ and I am attempting to compile a the tutorial code using VS code. I have looked all across the internet and I have not been able to find a tutorial that shows how to install SFML for VS code on a Mac. I have made a lot of progress but I am seemingly stumbling at the last hurdle after days of trying, so any help would be appreciated!

I downloaded the source code version of SFML and used cmake to build the libraries. This only produced dylib files. I created a src folder in my work environment and created two folders, lib and include within. I then moved the dylib files into the lib folder and the contents of the include folder into my include folder (Sorry if this is too much detail I just don't want to miss a step I where I made a mistake).

I then changed my task.json file so that the compiler path now read
"-fdiagnostics-color=always",
"-I${workspaceFolder}/src/include",
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L${workspaceFolder}/src/lib",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system""

Finally I moved the osx frameworks in the extlib folder to the Library/Frameworks folder on my mac. After all of this when I compile I produce an executable which provides the following error message:
dyld: Library not loaded: @rpath/libsfml-graphics.2.5.dylib
  Referenced from: /Users/myusername/Desktop/Cpp_Project/main
  Reason: image not found

I have been trying to get SFML to work for days and finally needed to cry for help! Any advice or tips would be greatly appreciated. Thank you!

P.S I have tried to add different combinations of the dylibs to my workspace folder but it hasn't made a difference.
« Last Edit: April 19, 2022, 01:25:54 pm by YaBoi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Problems linking to the libraries for VS code on a Mac
« Reply #1 on: April 14, 2022, 09:11:58 pm »
Are the dylibs next to your executable when you launch it?
Alternatively, you can install SFML in the common Library directory as well (I recommend building the install target, when build SFML).
And alternative alternatively, you can set rpath to tell your executable where to find the dylibs instead.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

YaBoi

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problems linking to the libraries for VS code on a Mac
« Reply #2 on: April 16, 2022, 06:27:16 pm »
Hi, thank you for your reply. I tried to run the executable with the a copy of the dylibs in the same folder as well as different combinations exclusively in the lib folder but nothing seemed to work. Currently I have all of my dylibs in a lib folder.

I am still new to C++ so I am unsure what you mean by building in the standard library? Is this when I do the cmake step? If so where can I find the standard library?

Similarly, I am unsure how to set my rpath manually, do I do that in VScode?

Thank you so much for your help, this has been a massive nightmare for me!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Problems linking to the libraries for VS code on a Mac
« Reply #3 on: April 19, 2022, 08:28:22 am »
I can't really fully walk you through the process, as I'm not experienced enough with a VS Code + macOS setup.

The simplest thing that should work is to install SFML, meaning when you build SFML there's a target called "install" that you can build, which not only builds SFML, but also copies all relevant files to their appropriate locations on your system, thus your compiler and linker should be able to find them, without additional configuration.

For understanding RPATH a bit more, check out one of my blog posts on said topic: https://dev.my-gate.net/2021/08/04/understanding-rpath-with-cmake/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

YaBoi

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problems linking to the libraries for VS code on a Mac
« Reply #4 on: April 19, 2022, 01:24:52 pm »
Thank you so much for your advice. I decided to install sfml using homebrew and changing my compiler path using this video: (in case anyone needs to use this thread for help later).

 

anything