undefined reference to `pthread_key_create' (linker error)
The option -lgtest
is attempting to link the dynamic library libgtest.so
. You
wish to link the static library /home/user/gtest-1.7.0/lib/.libs/libgtest.a
.
Instead of:
g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -lgtest -pthread
use:
g++ main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread
Note that your commandline supplies no name for the resulting executable, which will default
to a.out
. If you want it called, e.g. mytest
, then do:
g++ -o mytest main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread
undefined reference to `pthread_getspecific' when using cmake for googletest
There is a problem at link-time.
It is only an assumption: did you try this?
target_link_libraries(test gmock gtest pthread)
instead of your version:
target_link_libraries(test pthread)
target_link_libraries(test gmock)
target_link_libraries(test gtest)
undefined reference to `__gthrw___pthread_key_create with gcc 4.8.4 and Eclipse Luna
Found out that it is somehow related to g++-4.8.
I installed g++-5 and the error was gone.
Here are the steps:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-5 libstdc++-5-dev
sudo rm -f /usr/bin/g++
sudo ln -s /usr/bin/g++-5 /usr/bin/g++
Boost Libraries Linking Issues
Did you remember to specify -pthread
as well? From GCC manpage:
-pthread
Add support for multithreading using the POSIX threads library.
This option sets flags for both the preprocessor and linker.
It is required with code that uses POSIX threads.
Related Topics
Opencv Unable to Set Up Svm Parameters
How to Have Two Functions That Call Each Other C++
Static Member Access in Constant Expressions
Recommended Values for Opencv Detectmultiscale() Parameters
How Is the Std::Tr1::Shared_Ptr Implemented
Use Std::Fill to Populate Vector with Increasing Numbers
How to Define a String Literal in Gcc Command Line
Correct Usage(S) of Const_Cast<>
What Std::Locale Names Are Available on Common Windows Compilers
Why Is There No Support for Concatenating Std::String and Std::String_View
How to Provider User with Autocomplete Suggestions for Given Boost::Spirit Grammar
Order of Execution in Operator <<
Load the Same Dll Multiple Times
The New Keyword "Auto"; When Should It Be Used to Declare a Variable Type
Converting an Int to Std::String
Differencebetween Imagemagick and Graphicsmagick