Ask Your Question
4

gtest fuerte undefined reference when linking

asked 2012-05-14 21:42:24 -0600

Tinne De Laet gravatar image

updated 2012-05-15 00:12:25 -0600

Lorenz gravatar image

Hey all,

After upgrading to ubuntu precise and fuerte I have a problem when linking my unit tests based on gtest. I get an undefined reference to pthread_key_create (see below). Seems this is a problem of gtest (http://osdir.com/ml/googletestframework/2011-10/msg00028.html)? It seems that pthread is located in /lib/i386-linux-gnu/ in stead of /usr/lib. (output of: "find /lib /usr/lib -name 'pthread'" is "/lib/i386-linux-gnu/libpthread.so.0 /lib/i386-linux-gnu/libpthread-2.15.so") This is also disturbing since I have a 64 bit system (output of "uname -m" is "x86_64")

Any idea what to do?

Tinne

/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':
/usr/include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':
/usr/include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `~ThreadLocal':
/usr/include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
/usr/include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':
/usr/include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific'
/usr/include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
/usr/include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `~ThreadLocal':
/usr/include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
/usr/include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
/usr/include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific'
/usr/include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make[4]: *** [../bin/utest_positionCoordinates] Error 1
make[4]: Target `CMakeFiles/utest_positionCoordinates.dir/build' not remade because of errors.
make[4]: Leaving directory `/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl/build'
make[3]: *** [CMakeFiles/utest_positionCoordinates.dir/all] Error 2
make[4]: Entering directory `/home/fiep/test/geometric_relations_semantics/geometric_semantics_kdl ...
(more)
edit retag flag offensive close merge delete

Comments

I forgot to mention that this linking error does not occur on all my gtests. I have no idea however what the difference is between the different tests. Furthermore they are all part of the same ros package.

Tinne De Laet gravatar imageTinne De Laet ( 2012-05-16 01:48:46 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2012-05-16 05:46:16 -0600

Pascal gravatar image

Hi Tinner,

Under Ubuntu 11.10 I could fix the missing reference by adding this line to the CMakeList.txt file just above the rosbuild_add_gtest call: SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

Pascal

PS: solution found here: https://groups.google.com/forum/#!msg/googletestframework/0A0GkEOi8is/bg_ZDVm0tGEJ

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-05-14 21:42:24 -0600

Seen: 2,669 times

Last updated: May 16 '12