【发布时间】:2012-04-06 09:55:34
【问题描述】:
我们有一些应用程序链接到我们自己的几个库。我最近添加了一个链接到这些库的新应用程序,它可以在 Windows 上成功编译。
但是,在 Linux 上,我看到一个静态变量的“未定义引用”错误,这当然意味着该变量没有定义。错误发生在库中,但仅在链接到新应用程序时才会发生(现有应用程序仍然可以正常链接)。
如您所见,编译器说kAppVersion 未定义。实际上它是在Version.cpp 中定义的,并且common 是链接的(在CMakeLists.txt 中指定)。我们认为这可能与target_link_libraries 排序有关,但将common 移动到base(发生错误的位置)之前似乎没有任何效果。此外,在其他CMakeLists.txt(例如协同作用)中,排序似乎无关紧要,因为此应用程序编译成功。这个类似的问题似乎暗示订购很重要,但我对此没有任何成功:
问题:library is linked but reference is undefined
我唯一的想法是 synergyd.cpp 或 CDaemonApp.cpp 可能有问题——但我看不到任何明显的在 Linux 上编译但在 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
完整代码可从our repository浏览。
【问题讨论】:
标签: c++ compiler-errors cmake