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

Author Topic: SFML with GCC on MacOS  (Read 2254 times)

0 Members and 1 Guest are viewing this topic.

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML with GCC on MacOS
« on: October 06, 2024, 11:57:18 am »
I installed SFML on MacOS with
brew install sfml

a sample project compiles just fine with the default c++ compiler on MacOS which is Clang16 on my machine.
CMake's "find_package" works flawlessly and finds SFML. Great!
However, Clang 16 seems to not support C++20-Modules, so I installed Clang19 and GCC-14.2 via homebrew, which both do support Modules:
brew install llvm
brew install gcc

When i setup the Toolchain in Clion with these compilers i can run a hello-world example printing to std::cout without problems. However, the moment i include the SFML Libraries both Compilers give me a plethora of weird error messages.

I did the same thing with GCC-14.2 on Windows with the difference, that here i compiled SFML with that same GCC-14.2 Compiler and i can run the project using SFML and Modules on Windows.

So i assume that the installed version of SFML, that i got with brew, is not compatible with GCC-14.2  or Clang 19.
How would i proceed from here?
Is there a way to reinstall SFML with brew in a "GCC-14.2" or "Clang19" version? Or do i need to compile the SFML Source Code with one of these compilers and replace the files brew installed with the new files?
I cannot find anywhere information how to make brew installed libraries to work with other compilers. Maybe someone can give me a push in the right direction, thanks!

EDIT: I got it to compile after some detours.
1. I uninstalled the SFML version i got via brew with
brew uninstall sfml
2. I installed the newest llvm version (llvm 19) with brew:
brew install llvm
3. I added it to the path, so i could use the new compiler via the terminal

echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc

4. next i got the newest SFML version, compiling it with the new clang19 compiler and enabling shared libs and finally installed it:
git clone https://github.com/SFML/SFML.git
cd SFML
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DBUILD_SHARED_LIBS=ON
make
sudo make install
An interesting note: I was not allowed to compile it with GCC. CMake outright refused it with a message stating that SFML is only allowed to be compiled with clang on MacOS" or someting like that. Thats why i used Clang and not GCC for compiling SFML on MacOS.
All relevant SFML libraries were now being saved to /usr/local/lib
5. The CMakeLists.txt File looks like this:
cmake_minimum_required(VERSION 3.28)
project(myProject LANGUAGES CXX)

find_package(SFML COMPONENTS System Graphics)

set(SOURCES main.cpp)
include_directories(/Users/UserName/Documents/Programming/SFML/include)
add_executable(myProject ${SOURCES})
target_sources(myProject
        PUBLIC
        FILE_SET CXX_MODULES FILES
        Window.cppm
        Game.cppm
)
target_compile_features(myProject PRIVATE cxx_std_23)
target_link_libraries(myProject /Users/UserName/Documents/Programming/SFML/extlibs/libs-macos/Frameworks/freetype.framework/Versions/A/freetype SFML::System SFML::Graphics)
I had problems with FreeType which would not be recognized, even when installed via "brew install freetype". I had to link against the provided freetype file that comes with the SFML Source Code in the folder "extlibs". Also, despite find_package(...) being able to find SFML, the SFML Include Files were not available, thus i had to include them manually via "include_directories(...) in CMakeLists.txt. After that, the program finally compiled. I can now use C++ Modules with SFML 3 RC on my MacOS System.
« Last Edit: October 06, 2024, 09:24:06 pm by Grundkurs »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML with GCC on MacOS
« Reply #1 on: October 06, 2024, 10:07:45 pm »
GCC on macOS is causing issues with SFML, see https://github.com/SFML/SFML/issues/2790
We've added a failure, so people aren't trying and reporting the same issues over and over again.
If you have the patience, you can disable the check and see if you can find a workaround.

Is there a way to reinstall SFML with brew in a "GCC-14.2" or "Clang19" version?
Nope, you'll like need to rebuild SFML.

echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
You can also shorten the first part to the following, which will be more compatible over time:
Code: [Select]
"$(brew --prefix llvm)/bin"
I had problems with FreeType which would not be recognized, even when installed via "brew install freetype". I had to link against the provided freetype file that comes with the SFML Source Code in the folder "extlibs". Also, despite find_package(...) being able to find SFML, the SFML Include Files were not available, thus i had to include them manually via "include_directories(...) in CMakeLists.txt.
As a non-macOS user, I'm also a bit unsure what's the correct way. I guess if you must, you could also specify the library directory to search for, instead of hardcoding the path.

After that, the program finally compiled. I can now use C++ Modules with SFML 3 RC on my MacOS System.
🥳
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything