Issue
I've followed the steps described in Linking against GTest fails, and get this error.
CMake Error in src/impl/data_structures/simple_tree/CMakeLists.txt:
Imported target "GTest::GTest" includes non-existent path
"~/local/include/"
Further messages include:
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
EDIT: Although it loses "generality", I replaced the ~/
path with
the full path, and then get this error:
/usr/bin/ld: cannot find /home/myself/local/lib/: File format not recognized
The path exists, to be sure.
Solution
In your linked question, you are hinting to find_package()
where to find GTest with a few GTEST_*
variables. The library variables should provide the fully qualified name of the actual library file, not the location of the libraries. When you only provide the path, the FindGTest.cmake
module uses this path as the actual library when it wraps the imported targets; this is incorrect. Try modifying your CMake to something like this, then re-run CMake from scratch:
# adding googletest
set(GOOGLETEST_PATH /home/username/local/googletest)
set(GTEST_INCLUDE_DIR /home/username/local/include/)
set(GTEST_LIBRARY /home/username/local/lib/path/to/libgtest.a)
set(GTEST_MAIN_LIBRARY /home/username/local/lib/path/to/libgtest_main.a)
find_package(GTest REQUIRED)
For what it's worth, you really shouldn't have to set all of the variables before calling find_package()
. You should only need to set GTEST_ROOT
as suggested in this answer.
Answered By - Kevin