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

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to