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

Author Topic: Can't compile "SFML Works" example project on m1 Mac  (Read 12937 times)

0 Members and 1 Guest are viewing this topic.

PWGuy

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Can't compile "SFML Works" example project on m1 Mac
« on: February 03, 2021, 04:22:32 am »
I have a new M1 Mac (macOS Big Sur 11.2) and downloaded Visual Studio Code Insiders.  I installed SFML successfully using home-brew and have the "boiler plate" folder in place.  (Followed instructions in this video which worked great on my previous Intel Mac:

https://www.youtube.com/watch?v=XEGLsHp2bw0).

When I open the "boiler plate" folder, it loads the sample project.  When I try to build it, I get error below.

Is SFML not yet compatible w/ Apple Silicon?


Build & Run: Debug (target: sfml-vscode-boilerplate)

⇛  Linking: bin/Debug/sfml-vscode-boilerplate
ld: warning: ld: warning: ignoring file /usr/local/lib/libsfml-window.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64ld: warning: ignoring file /usr/local/lib/libsfml-network.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /usr/local/lib/libsfml-graphics.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

ignoring file /usr/local/lib/libsfml-audio.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /usr/local/lib/libsfml-system.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "sf::CircleShape::CircleShape(float, unsigned long)", referenced from:
      _main in Main.cpp.o
  "sf::RenderStates::Default", referenced from:
      _main in Main.cpp.o
  "sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)", referenced from:
      _main in Main.cpp.o
  "sf::RenderTarget::clear(sf::Color const&)", referenced from:
      _main in Main.cpp.o
  "sf::RenderWindow::RenderWindow()", referenced from:
      _main in Main.cpp.o
  "sf::RenderWindow::~RenderWindow()", referenced from:
      _main in Main.cpp.o
  "sf::Color::White", referenced from:
      _main in Main.cpp.o
  "sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)", referenced from:
      _main in Main.cpp.o
  "sf::Shape::setTexture(sf::Texture const*, bool)", referenced from:
      _main in Main.cpp.o
  "sf::Shape::setFillColor(sf::Color const&)", referenced from:
      _main in Main.cpp.o
  "sf::Shape::~Shape()", referenced from:
      sf::CircleShape::~CircleShape() in Main.cpp.o
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in Main.cpp.o
  "sf::Window::close()", referenced from:
      _main in Main.cpp.o
  "sf::Window::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in Main.cpp.o
  "sf::Window::display()", referenced from:
      _main in Main.cpp.o
  "sf::Window::pollEvent(sf::Event&)", referenced from:
      _main in Main.cpp.o
  "sf::Texture::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sf::Rect<int> const&)", referenced from:
      _main in Main.cpp.o
  "sf::Texture::Texture()", referenced from:
      _main in Main.cpp.o
  "sf::Texture::~Texture()", referenced from:
      _main in Main.cpp.o
  "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in Main.cpp.o
  "sf::RenderWindow::getSize() const", referenced from:
      _main in Main.cpp.o
  "sf::Window::getSystemHandle() const", referenced from:
      _main in Main.cpp.o
  "sf::Window::isOpen() const", referenced from:
      _main in Main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [bin/Debug/sfml-vscode-boilerplate] Error 1
make: *** [all] Error 2

✘  Failed!
   Review the compile errors above.


The terminal process "/bin/zsh '-c', 'bash ./build.sh buildrun Debug vscode'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.



I have confirmed that the Insiders version of Visual Studio Code for Mac (arm64) is compatible with Apple Silicon Macs.  Further, I THOUGHT I read somewhere (can't find source, sorry) that the C/C++ extension for Visual Studio Code wasn't yet Apple Silicon compatible but I'm not 100% sure now.

What else can I provide to help me figure this out?

Help!
« Last Edit: February 03, 2021, 04:43:09 am by PWGuy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #1 on: February 03, 2021, 01:01:13 pm »
Your issue probably boils down to:

I installed SFML successfully using home-brew

Homebrew most certainly hasn't gotten a arm64 version available for SFML, so you end up installed a x86_64 version, which then, as the linker tells you, is incompatible with your arm64 build.
If you want to build your application natively for arm64, you have no other choice than to build SFML and its dependencies (freetype, vorbis, flac, ogg, etc) for arm64 as well.
Alternatively you could maybe still get a x86_64 compiler and compile as before, but maybe that's not exactly what you want.

I'd be interested in hearing your experience with the M1 and SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PWGuy

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #2 on: February 04, 2021, 04:05:48 am »
Your issue probably boils down to:

I installed SFML successfully using home-brew

Homebrew most certainly hasn't gotten a arm64 version available for SFML, so you end up installed a x86_64 version, which then, as the linker tells you, is incompatible with your arm64 build.
If you want to build your application natively for arm64, you have no other choice than to build SFML and its dependencies (freetype, vorbis, flac, ogg, etc) for arm64 as well.
Alternatively you could maybe still get a x86_64 compiler and compile as before, but maybe that's not exactly what you want.

I'd be interested in hearing your experience with the M1 and SFML.

Thanks for the quick response - it's definitely more clear to me now!

However, I am unlikely to build SFML and its dependencies for arm64.  I have (non Insiders) VSCode working fine with x86_64 SFML installed - I will just keeping using it until we have a more "official" SFML build for arm64.

I'm really surprised it hasn't been done yet in the community, to be honest..

I have an M1 Mini and it is amazing - Rosetta 2 is real and translates extremely well!  I am very happy with it!  Further, as I said above, VSCode w/ SFML x86_64 installed works just fine, albeit a little memory intensive due to Rosetta 2, and a bit slower than x86, but all good!  It will be nice once SFML is provided via arm64 because VS Code Insiders (made for arm64) requires less memory and is extremely responsive!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #3 on: March 23, 2021, 08:20:40 pm »
Good news, I've just merged the dependency update PR, with that you should be able to use SFML on a device with an Apple M1 chip targeting arm64.

Additionally, a Mac Mini with an M1 chip has joined our CI fleet and is also publishing snapshot builds for those who don't want to build from source.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SRoland92

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #4 on: July 24, 2021, 10:09:20 am »
If you are still trying to compile SFML for M1, I just did it some minutes ago and I want to share my process:
  • git clone https://github.com/SFML/SFML.git
  • mkdir build
  • cd build
  • cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_OSX_ARCHITECTURES=arm64 ..
  • make all

Now, into your build folder you should find a "lib" directory with SFML arm64 libs.
In order to check that the libs have been compiled for Arm64 you can use "file" command :
file <library-name>.

Please let me know if you have problems linking the libraries in your project.
In my case I used Cmake, with target_link_libraries , like this :
target_link_libraries(particle PRIVATE ${CMAKE_SOURCE_DIR}/importedLibs/libsfml-graphics.dylib)

Have a nice day !

xavrr

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #5 on: September 10, 2021, 01:50:38 am »
Additionally, a Mac Mini with an M1 chip has joined our CI fleet and is also publishing snapshot builds for those who don't want to build from source.

Hi, after downloading the m1 version and setting it up as this tutorial says (https://www.sfml-dev.org/tutorials/2.5/start-osx.php), I still have the same errors as the first post made on this question.

What did I miss?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #6 on: September 10, 2021, 08:15:15 am »
If you have the same error, then that would indicate that your libraries are still only x86_64 and haven't actually been updated to use the universal builds or arm64 builds.

Are you certain you've replaced all the necessary libraries, including the SFML dependency frameworks?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mikeygoldman1

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Can't compile "SFML Works" example project on m1 Mac
« Reply #7 on: September 18, 2021, 03:04:18 pm »
Are there other options to get SFML to work on MacBook Air M1 without using CMAKE. I am a beginner in C++, so any help would be appreciated.
« Last Edit: September 18, 2021, 03:11:32 pm by Mikeygoldman1 »