[CMake] Add Windows library dependency

Theodore Hall twhall at umich.edu
Fri Jul 27 23:05:34 EDT 2018


Greetings,

I'm building a project that depends on a Windows library -- Secur32.Lib --
that is included in the regular library search path but is not one of the
specific libraries that the compiler normally links to.  In *NIX
command-line terms, the "-L<path>" is OK, I only need to specify the
"-lSecur32" part.

If I put "#pragma comment (lib, "Secur32.Lib")" in the cpp file, the system
finds and links it.  If I omit that, then the build fails with an
unresolved external symbol.

I cannot find a way to accomplish this in the CMakeLists.txt file rather
than relying on the #pragma.  CMake complains that it doesn't know how to
build it, though I've (tried to) set the IMPORTED property.  I've tried
various combinations of:

find_library(SECUR32 Secur32)
add_library(Secur32 SHARED IMPORTED)
target_link_libraries(MyTarget
Secur32)

I have not tried to set IMPORTED_LOCATION, because libraries with that name
exist in several locations, and the compiler actually knows better than I
do which one to use -- e.g., one of them is in:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64\Secur32.Lib

We're building in VisualStudio 2017 as a CMake project.  We have not
generated and are not using VS ",proj" or ".sln" files.  We're aiming to
build this as a multi-platform application.  (The dependence on this
library is wrapped in the appropriate #if defined ... #endif directives.)

Any enlightenment would be greatly appreciated.  Thanks.

-- 

Ted Hall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180727/4a948164/attachment.html>


More information about the CMake mailing list