user1053031
user1053031

Reputation: 747

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.

Upvotes: 12

Views: 10991

Answers (2)

lmc
lmc

Reputation: 23

I had a similar problem but with mpich. Both:

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

and

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

worked properly.

Upvotes: 1

thokra
thokra

Reputation: 2904

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

Upvotes: 13

Related Questions