only g++/linux - undefined reference to symbol 'dlclose@@GLIBC_2.2.5'


I know this might be a non-cmake related issue, but I cant figure out the problem. Giving it a shot here.
I build my c++ application using CMake on different platforms. It builds/compiles on windows ( visual studio and clang) and on mac-os (clang). However, on linux/g++ 8.3 I am getting a linker error:

/bin/ld: install_Linux/lib/MinVR-2.0/libMinVRd.a(VRSharedLibrary.cpp.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
//usr/lib64/ error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I’ve seen on stackoverflow that adding the ${CMAKE_DL_LIBS} variable to target_link_libraries would potentially fix the error. However, if I add it, other linker errors appear:

bin/ld: install_Linux/lib/libftgld.a(FTCharmap.cpp.o): undefined reference to symbol 'FT_Select_Charmap'

Again, the build/compile process works on windows and mac-os, but not on linux.

Ant thoughts ? I appreciate the help.

The latter implies that you are missing libraries which provide libfreetype symbols. I suspect that you’ve been getting along with behaviors that are automatic on the other two platforms until now (or settings are different).

So, should I add ${CMAKE_DL_LIBS} to target_link_libraries , and try to solve the link errors that appear?
Why it doesnt happen in other platforms?


Answering this would require more details about your specific project. There are linker flags that tell macOS to ignore undefined symbols, but the dependencies may also just be built differently there (or have some other library that is used altogether).

I solved this issue, and posting a note here in case someone finds themselves on this kind of error.

I was compiling my application using gcc 10.2 , but some 3rd party libraries were linking against a library that was build in gcc 4.3. One of the compiler flags I had it’s:


That statement causes link errors as documented on this link. Once I removed that definition, the program compiled successfully.