Search code examples
googletestgooglemockconan

Installing gtest with conan


I am about to change to conan, in the hope that is will simplify installing my package by my users. It was OK, until I started to add gtest to my package.

During install, I receive messages

gtest/1.8.1@bincrafters/stable: Package installed 
conanfile.txt imports(): Copied 4 '.a' files: libgmockd.a, libgtestd.a, libgmock_maind.a, libgtest_maind.a

However, during build I receive:

/usr/bin/ld: cannot find -lgmock_maind
/usr/bin/ld: cannot find -lgmockd
/usr/bin/ld: cannot find -lgtestd

My CMakeLists.txt file contains

target_link_libraries(
    ${PROJECT_NAME}_GTEST
    Modules
    ${CONAN_LIBS}
)

What is missing? Shall I provide some

link_directories(?)

argument?

(In the meantime, after some trials, I succeeded: Not only

 link_directories(${CONAN_LIB_DIRS_GTEST})

is needed, but also conan's .data must be cleared.)


Solution

  • What generator are you using?

    I have this in my conanfile.txt requires section

    gtest/[~=1.8]@bincrafters/stable
    

    This is what I have for generators in that section

    cmake_find_package
    cmake_paths
    

    And in the CMakeLists.txt

    include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
    find_package(gtest REQUIRED)
    add_dependencies(something gtest::gtest)
    target_link_libraries(something gtest::gtest)
    

    Note that FindGTest is a built in module, but Findgtest.cmake is a file generated by conan in the build directory.