pekingduck / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Issues with pthreads on compiling #391

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
IMPORTANT NOTE: PLEASE send issues or requests to
http://groups.google.com/group/googletestframework *instead of here*.
This issue tracker is NOT regularly monitored.

If you really need to create a new issue, please provide the information
asked for below.

What steps will reproduce the problem?
1.Download the gtest-1.6.0
2.cd to the make directory
3.run the `sample1_unittest`

What is the expected output? What do you see instead?
Normally, the build is suppose to go on without any errors. Instead, a list of 
missing references relating to pthreads are output.

What version of Google Test are you using? On what operating system?
Google test 1.6.0, GCC 4.6.1, Ubuntu 10.10 Oneiric Ocelot.

Please provide any additional information below, such as a code snippet.
It seems that in ubuntu 10.10, at the last stage of linking the gtest library 
and test source file, -pthread should be used instead of -lpthread.

Original issue reported on code.google.com by Briandkid on 21 Nov 2011 at 2:24

Attachments:

GoogleCodeExporter commented 9 years ago
this is due to the linker flag ld --as-needed being default in ubuntu.
the -lpthread must be placed after all objects needing its symbols or -pthread 
should be used.

Original comment by jtaylor....@googlemail.com on 2 May 2012 at 5:48

GoogleCodeExporter commented 9 years ago
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
It makes a difference where in the command you write this option; the linker 
searches and processes libraries and object files in the order they are 
specified

so we need to put -lpthread followed by objects or source file

I attached this patch

Original comment by Lynn.Xin...@gmail.com on 27 Sep 2012 at 6:37

Attachments:

GoogleCodeExporter commented 9 years ago
Quite a number of people are running into this issue. I did not have any 
problems under OSX 10.8.2 (perhaps because gcc are soft links to lvm), but as 
soon as I moved my code to Ubuntu 12.04 I ran into this issue.

Easy fix, but quite a hassle.

See http://stackoverflow.com/questions/10315016/error-during-making-gtest

Original comment by r...@burhum.com on 9 Dec 2012 at 7:26

GoogleCodeExporter commented 9 years ago
Some fix steps:
What steps will reproduce the problem?
1.Download the gtest-1.6.0
2.cd make/
3.make
4.PROFIT!...

Today i`m first try google test for C++ and have spend over hours to install 
it. Its quite wobbly to find a very OLD bug. And fix it.

$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -pthread $^ -o $@
-pthread should be used instead of -lpthread

Thanks for all users who have found this bug over two years ago!

Original comment by kiril.sa...@gmail.com on 29 Jul 2013 at 11:50