[cmake-developers] Shared library under Windows and CMake: DLL not found before installation
Craig Scott
craig.scott at crascit.com
Wed Feb 6 18:10:48 EST 2019
On Thu, Feb 7, 2019 at 7:11 AM Brad King via cmake-developers <
cmake-developers at cmake.org> wrote:
> On 2/6/19 2:40 PM, Joachim Wuttke wrote:
> > And combine it with
> >
> > ```
> > link_directories(BEFORE ${PROJECT_BINARY_DIR}/bin)
> > ```
> >
> > so that tests find the libraries?
>
> No. CMAKE_RUNTIME_OUTPUT_DIRECTORY only affects the locations of
> the .dll files, not .a/.so/.lib. Also CMake already knows where
> the library files will be and links via absolute path. Link
> directories are almost never needed.
>
> > Anyway, my problem is not at link time, but when _executing_ a test.
> > Is there a canonical way of manipulating the Windows PATH from CMake?
>
> No. In general one should not depend on PATH for .dll locations
> within your own project.
>
That's probably a bit strong, for very large projects it can be quite
inconvenient to have to put all executables and DLLs in the same directory.
For some scenarios, it's not a viable choice (can depend on the project's
directory layout requirements). There are a few ways to get this to work
for different scenarios, some depending on a more recent CMake version. For
tests run through CTest, The ENVIRONMENT test property can be used to
augment PATH on a test-by-test basis. For running under the Visual Studio
debugger, CMake 3.13 added the VS_DEBUGGER_ENVIRONMENT target property
which again can be used to set the PATH for a particular test executable
when run from within the VS IDE. If you need to support an older CMake
version, an equivalent functionality can be achieved with CMake 3.8 or
later using the VS_USER_PROPS target property, but this is more involved.
--
Craig Scott
Melbourne, Australia
https://crascit.com
Get the hand-book for every CMake user: Professional CMake: A Practical
Guide <https://crascit.com/professional-cmake/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20190207/54e78c58/attachment.html>
More information about the cmake-developers
mailing list