We have a few applications which link to several of our own libraries. I recently added a new application which links to these libraries, and this compiles successfully on Windows.
However, on Linux, I see an "undefined reference" error to a static variable, which of course means that the variable wasn't defined. The error occurs in a library, but only when linked to the new application (the existing applications still link fine).
As you can see, the compiler says that kAppVersion
is undefined. When actually it is defined in Version.cpp, and common is linked (specified in CMakeLists.txt). We thought that it may be something to do with target_link_libraries
ordering, but moving common
to before base
(where the error occurs) has no effect it seems. Besides, in other CMakeLists.txt (e.g. for synergys) the ordering appears to be irrelevant, as this application compiles successfully. This similar question appears to hint that ordering matters, but I haven't had any success with this:
Qustion: library is linked but reference is undefined
My only idea is that it could be something wrong in synergyd.cpp or CDaemonApp.cpp -- but I can't see anything obvious that compiles on Linux but not Windows.
Scanning dependencies of target synergyd
[ 90%] Building CXX object src/cmd/synergyd/CMakeFiles/synergyd.dir/synergyd.o
Linking CXX executable ../../../../../bin/debug/synergyd
../../../../../lib/debug/libarch.a(CArch.o): In function `~XExitApp':
/srv/buildbot/synergy/1.4-linux32/build/src/lib/arch/../synergy/XSynergy.h:114: undefined reference to `vtable for XExitApp'
../../../../../lib/debug/libarch.a(CArch.o): In function `CArchAppUtil::exitApp(int)':
/srv/buildbot/synergy/1.4-linux32/build/src/lib/arch/CArchAppUtil.h:31: undefined reference to `XExitApp::XExitApp(int)'
/srv/buildbot/synergy/1.4-linux32/build/src/lib/arch/CArchAppUtil.h:31: undefined reference to `typeinfo for XExitApp'
../../../../../lib/debug/libarch.a(CArchAppUtilUnix.o): In function `CArchAppUtilUnix::parseArg(int const&, char const* const*, int&)':
/srv/buildbot/synergy/1.4-linux32/build/src/lib/arch/CArchAppUtilUnix.cpp:32: undefined reference to `CApp::isArg(int, int, char const* const*, char const*, char const*, int)'
/srv/buildbot/synergy/1.4-linux32/build/src/lib/arch/CArchAppUtilUnix.cpp:37: undefined reference to `CApp::isArg(int, int, char const* const*, char const*, char const*, int)'
../../../../../lib/debug/libbase.a(CLog.o): In function `CLog::insert(ILogOutputter*, bool)':
/srv/buildbot/synergy/1.4-linux32/build/src/lib/base/CLog.cpp:213: undefined reference to `kAppVersion'
collect2: ld returned 1 exit status
make[2]: *** [../../bin/debug/synergyd] Error 1
make[1]: *** [src/cmd/synergyd/CMakeFiles/synergyd.dir/all] Error 2
make: *** [all] Error 2
The full code can be browsed from our repository.