Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error during making GTest

I was trying to set up GTest environment on my Ubuntu machine. but while making the GTest to get the library, i get the following error...

som@som-VPCEH25EN:~/Workspace/CPP/gtest-1.6.0/make$ make g++ -I../include -g -Wall -Wextra -lpthread sample1.o sample1_unittest.o gtest_main.a -o sample1_unittest gtest_main.a(gtest-all.o): In function `~ThreadLocal': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific' /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete' /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific' /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete' gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific' /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific' gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create' gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create' gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific' /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific' collect2: ld returned 1 exit status make: *** [sample1_unittest] Error 1 
like image 672
somenath mukhopadhyay Avatar asked Apr 25 '12 11:04

somenath mukhopadhyay


People also ask

How do I skip a Gtest test?

The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).

How do I run a Gtest in Xcode?

Open your project in Xcode. You can do it from AppCode by selecting File | Open Project from Xcode from the main menu. Select the project in the project navigator, then select the target and open the Build Phases tab. In the Link binary with libraries section, select the generated libgtest.


1 Answers

Try moving -lpthread to after gtest_main.a in your g++ command.

like image 86
Fraser Avatar answered Oct 04 '22 04:10

Fraser