简体   繁体   English

CMake项目建设问题

[英]Issue with CMake project building

I have the following problem. 我有以下问题。 On my Ubuntu I try to build a project and receive the following linker error(s) so far: 在我的Ubuntu上,我尝试构建一个项目并收到以下链接器错误:

/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_thread.a(once.o): undefined reference to symbol 'pthread_once@@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO
missing from command line collect2: error: ld returned 1 exit status
make[2]: *** [sunprint] Error 1 make[1]: ***
[CMakeFiles/sunprint.dir/all] Error 2 make: *** [all] Error 2
*** Failure: Exit code 2 ***

I'm running under ubuntu 13 desktop, GCC 4.8, boost ver. 我在ubuntu 13桌面,GCC 4.8,boost ver下运行。 is 1.54. 是1.54。 As an IDE I'm working with is the KDevelop. 作为我正在使用的IDE是KDevelop。 I can provide any additional info about this issue if needed, but now I'm stuck with this linking problem. 如果需要,我可以提供有关此问题的任何其他信息,但现在我遇到了这个链接问题。

Any ideas? 有任何想法吗? Thanx in advance. Thanx提前。

add_definitions only adds inputs for the preprocessor, which is in action even before the compiler starts its business and even much farther away from linking the executable, the step ld is supposed to be doing. add_definitions只为预处理器添加输入,甚至在编译器开始其业务之前就已经开始运行,甚至更远离链接可执行文件,步骤ld应该正在执行。

What you want to have ld resolve link-time dependencies is the CMake command target_link_libraries , which, for a given target, add a number of libs to link against after compilation. 你想拥有什么ld决心链接时的依赖是CMake的命令target_link_libraries ,其中,对于给定的目标,增加了许多库的打击编译后链接。

In you case, the appropriate invocation could look like this 在您的情况下,适当的调用可能如下所示

target_link_libraries(${PROJECT_NAME} [...] -lpthread [...]) #obviously without the '[...]' and the correct target name

I had a similar problem but with mpich . 我有一个类似的问题,但与mpich Both: 都:

target_link_libraries(${PROJECT_NAME} [...] -lmpich [...])

and

target_link_libraries(${PROJECT_NAME} [...] mpich [...])

worked properly. 工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM