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

Author Topic: Mac M1: Undefined symbols for architecture arm64 with manually compiled libs  (Read 2865 times)

0 Members and 1 Guest are viewing this topic.

shvp

  • Newbie
  • *
  • Posts: 3
    • View Profile
I would really appreciate any help with that. That code is simple as it can be
#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");
}

The setup is VS Code & C/C++ Extension v1.9.5
g++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.2.0

Full error message goes like this:
> Executing task: Start Build <

Starting build...
/usr/bin/g++ -fdiagnostics-color=always -I /usr/local/include -L /Users/DG/cppurgatory/SFML_repo/lib -g /Users/DG/cppurgatory/helloworld/*.cpp -o /Users/DG/cppurgatory/helloworld/bin/run -std=c++17
Undefined symbols for architecture arm64:
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in helloworld-5735a7.o
  "sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in helloworld-5735a7.o
  "sf::Window::~Window()", referenced from:
      _main in helloworld-5735a7.o
  "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in helloworld-5735a7.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Build finished with error(s).

I tried to follow this topic, but as original poster I still can't figure this out: https://en.sfml-dev.org/forums/index.php?topic=27867.0

I've compiled libs as it was suggested there. Here you can see that they are actually arm64:
~ % cd /Users/DG/cppurgatory/SFML_repo/lib
DG@MBP-SHVP lib % file libsfml-audio.3.0.0.dylib
libsfml-audio.3.0.0.dylib: Mach-O 64-bit dynamically linked shared library arm64

Running this tasks.json:
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-I",
                "/usr/local/include",
                "-L",
                "/Users/DG/cppurgatory/SFML_repo/lib",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${workspaceFolder}/bin/run",
                "-std=c++17",
            ],

With c_cpp_properties.json configuration:
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Users/DG/cppurgatory/SFML_repo/lib",
                "/usr/local/include"
            ],
            "defines": [],
            "macFrameworkPath": ["/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-gcc-arm64",
            "forcedInclude": []
       

Any thoughts? Been struggling for two days already. I really want write some actual code already

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Looks like you're trying to link 64-bits SFML libraries while compiling for arm64.
Make sure to either use the snapshot builds for arm64 or when building SFML yourself, to set the architecture to arm64.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shvp

  • Newbie
  • *
  • Posts: 3
    • View Profile
when building SFML yourself, to set the architecture to arm64.

So dylib I built showing:
DG@MBP-SHVP lib % file libsfml-audio.3.0.0.dylib
libsfml-audio.3.0.0.dylib: Mach-O 64-bit dynamically linked shared library arm64

I'll try snapshot anyways. Thanks!


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Ah, I might have misunderstood the file message.

Looking at the issued command, you're never actually linking SFML, plus you're using g++ and not clang / AppleClang.

/usr/bin/g++ -fdiagnostics-color=always -I /usr/local/include -L /Users/DG/cppurgatory/SFML_repo/lib -g /Users/DG/cppurgatory/helloworld/*.cpp -o /Users/DG/cppurgatory/helloworld/bin/run -std=c++17

See the g++ usage here and the lack of -lsfml-xyz flags.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shvp

  • Newbie
  • *
  • Posts: 3
    • View Profile
I really appreciate your help! I managed to create a window.
So I'm still using g++. What does a trick:

 
                ...
                "-L",
                "/usr/local/lib",
                "-lsfml-system",
                "-lsfml-window",
                "-lsfml-graphics",
                "-lsfml-network",
                "-lsfml-audio",
                 ...

+ moved FLAC, freestyle, freestyle folders and other ext dependencies from arm64 snapshot you posted to /Library/Framework
Cheers!

 

anything