I’ve compiled Google C++ Test. I’m now trying to add it to my g++ installation (on Cygwin) such that I don’t have to specify -I, -L, and -l for every project. The steps I did were:
- I put a symlink in /usr/local/include to GTEST_ROOT/include/gtest
- I put symlinks in /usr/local/lib to the libs in GTEST_ROOT/lib (libgtest.la libgtest_main.la)
- I wrote a proof program to test the setup
The test program compiles fine with g++ -c proof.cpp but g++ proof.cpp gives errors during the linking, saying that the gtest references can’t be found.
Using grep to search my GTEST_ROOT for the required references, I found them in additional libs in GTEST_ROOT/lib/.libs (libgtest.a libgtest.la libgtest.lai libgtest_main.a libgtest_main.la libgtest_main.lai)
Due to time constraints, I got it to work using the following command g++ -LGTEST_ROOT/lib/.libs -lgtest proof.cpp and I’ve put this in a makefile.
However, I’m still trying to get my setup such that g++ proof.cpp would just work. What am I missing?
Thanks to Matt, I understand now that I cannot drop the -lgtest. I would like to at least get rid of the -LGTEST_ROOT/lib/.libs. I’ve added symlinks to the additional .a and .lai files provided. However, g++ proof.cpp -lgtest now gives me the linker error: cannot find -lgtest
NOTE: symlinking the libs in GTEST_ROOT/lib/.libs still does not give the desired results.
You’ll always need to pass
-lgtestto your final compile/link step1. GCC will not search all the libraries in its search path for the symbols that it is missing (that would be way too expensive).The library files themselves (
.soor.a) need to be in the/usr/local/lib/directory, or a symlink to those files. Symlinking a directory there will not work.1well, that’s not technically true. You could modify your spec file, but don’t do that.