[CMake] IMPORTED DLL-only Target on MSVC

Mueller-Roemer, Johannes Sebastian Johannes.Sebastian.Mueller-Roemer at igd.fraunhofer.de
Tue Apr 3 03:59:03 EDT 2018


>From the CMake side of things yes, but MSVC requires an import library. You could use a tool such as Digital Mars' implib tool (https://digitalmars.com/ctg/implib.html), or use dumpbin to list all exports, put those in a .def file and use lib to create an import library from the def file. If I am not mistaken, CMake's GNUtoMS switch (for the Mingw Makefiles generator) does something like this automatically, so you could have a look at how it is done there. But I assume it's simply parsing the dumpbin /exports output to write a def file and running lib afterwards.

Regards,
Johannes

Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roemer at igd.fraunhofer.de | www.igd.fraunhofer.de

-----Original Message-----
From: CMake <cmake-bounces at cmake.org> On Behalf Of Marek Vojtko (Firaxis)
Sent: Tuesday, April 3, 2018 00:49
To: cmake at cmake.org
Subject: [CMake] IMPORTED DLL-only Target on MSVC

Hi,

Is it not possible to wrap an external DLL-only library in an IMPORTED target?

I have an external dependency that is a single DLL (shared library) and a header file, but no LIB (static library) file. When I create an IMPORTED target and depend on it via target_link_libraries() I run into linkage issues, because on MSVC CMake puts the DLL into the linker command (the "Input" text field in the "Linker" settings of the Project Properties).

add_library( MyDependency::MyDependency MODULE IMPORTED ) set_target_properties( MyDependency::MyDependency
    PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${MyDependency_INCLUDE_DIR}"
        IMPORTED_LOCATION "${MyDependency_SHARED_LIB}"
)
[..]
add_executable( MyExecutable ... )
target_link_libraries( MyExecutable PRIVATE MyDependency::MyDependency )

I tried changing the library type in my add_library() call:
- STATIC obviously didn't work, because I don't have a .lib file and the .dll file in IMPORTED_LOCATION was added to MyExecutable's linker line.
- SHARED did not work because CMake expects a .dll in IMPORTED_LOCATION and a .lib in IMPORTED_IMP_LOCATION, so MyExecutable's linker line had a MyDependency::MyDependency-NOTFOUND entry in it.
- MODULE seemed like the right choice when reading the documentation, but MyExecutable's linker line still contains the .dll file specified in IMPORTED_LOCATION.

What am I doing wrong?

Thanks,
Marek

-- 

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


More information about the CMake mailing list