0

I am using MacBook with M1 and I try to create a project with SFML. I downloaded a snapshot of SFML with files built for arm64

I verified it using file command Example: libsfml-graphics.dylib: Mach-O 64-bit dynamically linked shared library arm64

I placed these files in ~/Library/Frameworks along with extlibs directory content.

I set a CMake flag: -DCMAKE_OSX_ARCHITECTURES=arm64

But I still am unable to run this project. Error:

[ 50%] Linking CXX executable myProject
Undefined symbols for architecture arm64:
  "__ZN2sf6StringC1EPKcRKSt6locale", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make[3]: *** [myProject] Error 1
make[2]: *** [CMakeFiles/myProject.dir/all] Error 2
make[1]: *** [CMakeFiles/myProject.dir/rule] Error 2
make: *** [myProject] Error 2

This is my whole CMakeLists.txt file:

cmake_minimum_required(VERSION 3.19)
project(myProject)

add_executable(myProject main.cpp)

set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-11" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_OSX_ARCHITECTURES=arm64")

include_directories(/usr/local/include)

find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED)
include_directories(${SFML_INCLUDE_DIRS})
target_link_libraries(myProject sfml-system sfml-window sfml-graphics sfml-audio sfml-network)

I also tried to use dylib instead of framework, but it was unsuccessful also. I'd be grateful for any help, I can't figure out what I did wrong.

Wiktor
  • 726
  • 5
  • 20
  • [CMAKE_OSX_ARCHITECTURES](https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_ARCHITECTURES.html) is **CMake variable**. Setting it as a compiler **macro definition** (via variable `CMAKE_CXX_FLAGS`) has no sense. Note also, that documentation for variable explicitly tells, that the variable should be set prior the `project()` call. Setting a compiler (CMAKE_CXX_COMPILER) after the `project()` is wrong too: https://stackoverflow.com/a/63944545/3440745. – Tsyvarev Nov 23 '21 at 08:38
  • Thank you for your response @Tsyvarev According to your advice, I deleted `CMAKE_CXX_COMPILER` and set it as CMake options in CLion. It seems to identify it properly. I also read about CMAKE_OSX_ARCHITECTURES, and if I understand everything well I should add this before project(): `set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Architecture" FORCE)` I did so, but nothing had changed. – Wiktor Nov 23 '21 at 10:03

0 Answers0