Linux Linking Issue: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'

Hi,
I'm trying to compile our projects' linux version with the Photon SDK but I'm getting the following error :
/usr/bin/ld: ../sdks/photon-linux/Common-cpp/libCommonDebug64.a(CustomTypeBase.o): undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm building with CLang and Cmake, below are the flags I'm using :
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -DLINUX -fsigned-char -fexceptions")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
Any help would be greatly appreciated !

Comments

  • According to this, it might be because I'm building using clang and libc++ but the photon SDK is built with GCC and libstdc++.
    Is there anyway to get photon build with CLang / libc++ as well ?

    https://stackoverflow.com/questions/20700630/boost-linking-error-undefined-reference-to-glibcxx-3-4
  • Hi @MadZaf.

    I agree that this is very likely the reason for the error.

    Unfortunately currently we only support g++ on Linux, but not clang.
  • MadZaf
    MadZaf
    edited March 2019
    Hi @Kaiserludi

    So apparently adding -Wl,--copy-dt-needed-entries to the Linker flags solved it.

    So it might just be an ordering issue.
    I'll do some more testing tomorrow. I hope that's it because I cannot build the project with g++ unfortunately.
    Thank you for your answer.
  • @MadZaf

    Thank You for sharing that "magic" linker flag that worked for me on Android as well. I tried to link libc++ libraries under Android Studio with NDK 16b. It gave me a lot of strange link errors like "undefined reference to 'std::ios_base::Init::Init()'" and many undefined references, where they are well defined in source code and it compiles on Windows and iOS.
    I added -Wl,--copy-dt-needed-entries then it complied on Android. But when I removed that option, got same errors as before, but tried to change photon libraries link order, and changed it 3 times. After third change, when I reverted libraries order in CMakeLists.txt as it was from beginning, it somehow started to build even without "-Wl,--copy-dt-needed-entries". It's strange, but now it can build successfully. I'll try it on another PC, maybe that linker option is needed after all to make it link after Photon upgrade. And it's not dirty build cache, I tried to clean it and rebuild many times. Maybe it's a case when just "clean" doesn't work...
  • Hi @User228.

    When you get the error on Android, that typically indicates a standard library mismatch between libc++ (the clang standard library) and libstdc++ (the GCC standard library) as in your app gets built against one of those two, but links against a variant of the Photon libs that has been built against the other one.
    Make sure to link against the Photon libs with the "_libc++" postfix in their names when using the clang standard lib in your app, and against the ones without it, when using the GCC standard lib.

    Please see https://forum.photonengine.com/discussion/comment/46415/#Comment_46415 for more information.
  • @Kaiserludi
    Thank You!
    I think it was Android Studio build cache issue, coz on another PC I deleted app/build folder and it compiled fine without "-Wl,--copy-dt-needed-entries".