Issue
I follow this post
to setup gtest 1.7 on eclipse cdt 8.2.1.but got this errors:
....test/AllTests.bc src/Test.bc -lgmock -lgtest -lpthread -lstdc++
/usr/bin/ld: cannot find -lgmock
/usr/bin/ld: cannot find -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Info: Parallel threads used: 3
By the way,there is some change from gtest 1.5 to 1.7,I actually make link like this:
sudo ln -s lib/.libs/libgtest.a /usr/lib/libgtest.a
As you can see,libgtest is under gtest1.7/lib/.lib(the second hidden dir) not gtest1.7/lib. so what did I do wrong?
Solution
You appear to have attempted to make symbolic links to libgtest.a
and libgmock.a
by using the commands:
sudo ln -s lib/.libs/libgtest.a /usr/lib/libgtest.a
sudo ln -s lib/.libs/libgmock.a /usr/lib/libgmock.a
from the console in /your/path/to/gtest-1.7.0
and /your/path/to/gmock-1.7.0
respectively.
If you open /usr/lib
in your file manager, find the links libgtest.a
and libgmock.a
and exam their properties, I believe you will find that
these links are broken, and that is why the linker cannot find them
in your project. Your ln
commands give relative paths to their targets,
but absolute paths are needed.
If so, delete the broken links and recreate them with the commands:
sudo ln -s /full/path/to/gtest-1.7.0/lib/.libs/libgtest.a /usr/lib/libgtest.a
sudo ln -s /full/path/to/mock-1.7.0/lib/.libs/libgmock.a /usr/lib/libgmock.a
E.g on my system /full/path/to/
= /home/imk/develop/
Then I think your build will work.
However, creating these symbolic links in /usr/lib
slightly taints your
system installation. It would be better to create them in /usr/local/lib
.
Or even simpler, you can just add these static libraries to the object files
for your project linkage:
In Eclipse, navigate your project -> Properties -> C/C++ build -> Settings -> your compiler Linker -> Libraries and delete
gmock.a
,gtest.a
Immediately under Libraries you find Miscellaneous. There, in Other objects, add:
/full/path/to/libgtest.a
/full/path/to/libgmock.a
All these suggestions have worked for me.
Answered By - Mike Kinghan
Answer Checked By - Senaida (JavaFixing Volunteer)