[CMake] how to link a test with library in build directory, not with installed version?

Joachim Wuttke j.wuttke at fz-juelich.de
Mon May 27 11:51:54 EDT 2019


How to link a test with a library as obtained in the build directory,
not with the installed version, which may be outdated?

Disclosure: cross-posted from https://stackoverflow.com/questions/56328326.

== Use case ==

Suppose

   cmake; make; ctest; make install

works fine:
- generates libA,
- runs testB,
- installs libA to ${CMAKE_INSTALL_LIBDIR}.

Now I modify libA, and rerun
   make; ctest.
No reaction to my modifications:
   ldd testB
shows that the installed version of libA is used.
Which is plain nonsense for a test.

The test should always use the local version of libA, never the installed one.

== Towards a solution ==

I saw a lot of advise that involves RPATH, but found no variant that helps.

So I hard-coded the path by changing
   target_link_libraries(testB PRIVATE A)
into
   target_link_libraries(testB PRIVATE ${CMAKE_BINARY_DIR}/lib/libA.so).

This works, but is no longer platform independent.
How to solve my problem in a way that also works under Windows?

- Joachim

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5110 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://cmake.org/pipermail/cmake/attachments/20190527/2ea52c36/attachment.bin>


More information about the CMake mailing list