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

Author Topic: SFML with cmake linker error? (OSX)  (Read 1313 times)

0 Members and 1 Guest are viewing this topic.

imdumb

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML with cmake linker error? (OSX)
« on: April 13, 2021, 05:55:43 pm »
So I'm having this problem where if I try to compile the code with cmake on my mac, it throws an error that it can't load some resources.

Code: [Select]
[100%] Linking CXX executable bird
Undefined symbols for architecture x86_64:
  "__ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN13ResourceCache16loadFontResourceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_ in libBird_core.a(ResourceCache.cpp.o)
  "__ZN2sf6StringC1EPKcRKSt6locale", referenced from:
      __ZN9__gnu_cxx13new_allocatorIN2sf12RenderWindowEE9constructIS2_JNS1_9VideoModeERA11_KcNS1_5Style9._anon_74ERNS1_15ContextSettingsEEEEvPT_DpOT0_ in libBird_core.a(Game.cpp.o)
  "__ZN2sf6StringC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6locale", referenced from:
      __ZN19PlayingMenuActivity6updateERKf in libBird_core.a(PlayingMenuActivity.cpp.o)
      __ZN6Button9setStringERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libBird_core.a(Button.cpp.o)
  "__ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE", referenced from:
      __ZN13ResourceCache19loadTextureResourceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_ in libBird_core.a(ResourceCache.cpp.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [bird] Error 1
make[1]: *** [CMakeFiles/bird.dir/all] Error 2
make: *** [all] Error 2

The code works on Windows and Linux so I don't think its an issue with the code, but with how I've linked stuff.

I think the difference is in my CMakeLists.txt file. Before it was using xcode's gcc to compile (and it would not compile) and so I changed it by changing these lines.

Code: [Select]
###########################
# CMake Build Environment #
###########################
#
# You can set the following Environment variables:
#
# CMAKE_MODULE_PATH to the search path for cmake modules (e.g., SFML.cmake)
# CMAKE_BUILD_TYPE to override the default build type. Valid options are 'release', 'profile' and 'debug'
#
#########################################


set(CMAKE_C_COMPILER "gcc-10")
set(CMAKE_CXX_COMPILER "g++-10")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_CXX_STANDARD 11)



Any help would be appreciated!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML with cmake linker error? (OSX)
« Reply #1 on: April 13, 2021, 07:04:55 pm »
Personally, I'd recommend sticking with Xcode/clang

The std::string ABI was changed in GCC for C++11.
So you need to make sure SFML is compiled with the same runtime than your application is.
And/or can try to enable/disable the C++11 standard for your code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/