Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

/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. is 1.54. As an IDE I'm working with is the 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.

like image 971
user1053031 Avatar asked Nov 11 '13 09:11

user1053031


People also ask

How do I build a project using CMake?

To build with just cmake change directory into where you want the binaries to be placed. For an in-place build you then run cmake and it will produce a CMakeCache. txt file that contains build options that you can adjust using any text editor.

How does CMake build work?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.

Is there something better than CMake?

There are more than 25 alternatives to CMake for a variety of platforms, including Linux, Mac, Windows, BSD and Xcode. The best alternative is GNU Make, which is both free and Open Source. Other great apps like CMake are Maven, Premake, SCons and Ninja Build.


1 Answers

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.

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.

In you case, the appropriate invocation could look like this

target_link_libraries(${PROJECT_NAME} [...] -lpthread [...]) #obviously without the '[...]' and the correct target name
like image 172
thokra Avatar answered Oct 06 '22 02:10

thokra