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

Author Topic: VS Code running simple sfml app macos  (Read 1551 times)

0 Members and 1 Guest are viewing this topic.

abp54

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
VS Code running simple sfml app macos
« on: December 09, 2023, 01:10:38 am »
I have downloaded sfml and installed the libraries and include files in my project folder. I built task.json file and all is good. All the libraries and include files are found. It builds just fine but will not link with the following error:

dyld[26832]: Symbol not found: __ZN2sf6StringC1EPKcRKNSt3__16localeE
  Referenced from: <9D94329C-AD52-32F9-8EC3-F5817B408DDC> /Users/Anthony/projects/sfmltest/app
  Expected in:     <no uuid> un

Anyone else run into this. I can't seem to figure it out. I am new to sfml and a bit rusty on my c so any help would be appreciated.

Thrasher

  • SFML Team
  • Jr. Member
  • *****
  • Posts: 57
    • View Profile
Re: VS Code running simple sfml app macos
« Reply #1 on: December 09, 2023, 03:55:17 am »
https://www.sfml-dev.org/tutorials/2.6/start-cmake.php

Try using the CMake project template and see if that's any easier for you. It's a lot easier to use.

abp54

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: VS Code running simple sfml app macos
« Reply #2 on: December 10, 2023, 12:04:21 am »
What I really would like to know is what are the required libraries to link with macos g++.
It seems to me that:

g++ main.cpp -o appname -I<path to includes> -L<path to libraries> should work. I have seen it work in several tutorials. I just get path not found and I have done ls on the path and it is correct. Is it something to do with the .dylib extension. Does g++ appending something to the file name.
 
How do the Framework versions differ?

I would not reach out but I have been thru every tutorial I could find and everyone of them fail.
Maybe my mac is corrupted or I am just really missing something.

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: VS Code running simple sfml app macos
« Reply #3 on: December 10, 2023, 04:07:38 am »
g++ main.cpp -o appname -I<path to includes> -L<path to libraries>
This is missing linking any libraries though. -L says where libraries are, but -l says which libraries to link.
From what I see in your tasks.json, none of the sfml libraries have -l, so they aren't being linked.

Although I don't do mac dev, so I don't know anything about dylibs or tasks.json, just guessing here. :)

abp54

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: VS Code running simple sfml app macos
« Reply #4 on: December 10, 2023, 08:36:49 pm »
Thank you for the reply. This is the actual command.

g++ -o app -I/usr/local/opt/sfml/include -L/usr/local/opt/sfml/lib -llibsfml-graphics.2.6.1.dylib -llibsfml-window.2.6.1.dylib -llibsfml-system.2.6.1.dylib

result:
ld: library 'libsfml-graphics.2.6.1.dylib' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And from my project folder

[Anthony@:~/projects/abp]$ ls /usr/local/opt/sfml/lib
cmake                        libsfml-audio.dylib          libsfml-graphics.dylib       libsfml-network.dylib        libsfml-system.dylib         libsfml-window.dylib
libsfml-audio.2.6.1.dylib    libsfml-graphics.2.6.1.dylib libsfml-network.2.6.1.dylib  libsfml-system.2.6.1.dylib   libsfml-window.2.6.1.dylib   pkgconfig
libsfml-audio.2.6.dylib      libsfml-graphics.2.6.dylib   libsfml-network.2.6.dylib    libsfml-system.2.6.dylib     libsfml-window.2.6.dylib

The path is correct and the libraries are there. Can't for the life of me see why compiler tells me they are not found.

And the full invocation:
[Anthony@:~/projects/abp]$ g++ -v -o app -I/usr/local/opt/sfml/include -L/usr/local/opt/sfml/lib -llibsfml-graphics.2.6.1.dylib -llibsfml-window.2.6.1.dylib -llibsfml-system.2.6.1.dylib
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: x86_64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 13.0.0 14.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o app -L/usr/local/opt/sfml/lib -L/usr/local/lib -llibsfml-graphics.2.6.1.dylib -llibsfml-window.2.6.1.dylib -llibsfml-system.2.6.1.dylib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.osx.a
ld: library 'libsfml-graphics.2.6.1.dylib' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Regards



abp54

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: VS Code running simple sfml app macos
« Reply #5 on: December 10, 2023, 08:55:41 pm »
Found it!!!

On systems where you use libX.a (or libX.so, or libX.dylib like on macOS) libraries, the name of the library is X.

You should not include the lib prefix or the suffix (.a or .so or .dylib). Those are added by the linker automatically when searching for the library.

The name of the sfml-graphics.2.5.1 library is just that, and it's the name you should use: -lsfml-graphics.2.5.1

Live and learn.
Thanks