0

I am using gtest for my library. I have two CMakeLists.txt, one for the main project and another one for the tests. In the main CMakelists.txt, I set

add_library(myLib::myLib ALIAS ${TARGETS_LIB_NAME})

Then in the gtest CMakeLists.txt, I link it as

target_link_libraries(test1 myLib::myLib)

But it keeps linking to installed version of myLib, not the one that is just built. Whenever I modify the header file, I have to delete the installed library in order to build the tests. What is a proper way to do this?

ultrafrog
  • 183
  • 6
  • 1
    `${TARGETS_LIB_NAME}` should be the target name, not library file name. – numzero Mar 29 '20 at 01:29
  • Are you sure it *links* with the wrong library? Or it uses wrong include files? – numzero Mar 29 '20 at 01:30
  • Instead of *describing* your code, **show** that code. Even if the wording you use in the question post is correct, then your *description* could be interpreted in a **several ways**. If you suspect linking to unexpected library, then show the link command line (`make VERBOSE=1`). – Tsyvarev Mar 29 '20 at 08:01
  • @numzero that {TARGETS_LIB_NAME} is also the target name. It actually includes wrong directories (both but this error is caused by the include path). – ultrafrog Mar 29 '20 at 08:29
  • So the problem is with include directories. Did you use `target_include_directories` on myLib? – numzero Mar 29 '20 at 15:11
  • @numzero no I didn't. target_link_libraries should do this, right? – ultrafrog Mar 31 '20 at 21:17
  • I meant `target_include_directories(${TARGETS_LIB_NAME} INTERFACE...` (or `PUBLIC`). That’s what you use to let `target_link_libraries` do its job later. So show all the `target_include_directories` and `target_link_libraries` commands on the relevant targets, please, and also file paths, both actual (from the cmake project root at least) and used in `#include`s. – numzero Apr 08 '20 at 22:55

0 Answers0