Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link against Windows system libraries with CMake?

I am building a simple Windows application that needs to link against gdiplus and winmm.
Previously I was using

find_library(GDIPLUS gdiplus)
target_link_libraries(target ${GDIPLUS})

but CMake does not find the library when using the Visual Studio 2015 target with the Visual C++ Build Tools. According to the answer here I should probably drop the find_library and just use

target_link_libraries(target gdiplus.lib)

but I'm not sure if this will only work for Visual Studio or for example also with Cygwin.
So what is the correct (or best) way to link against Windows system libraries from CMake?

like image 774
eyelash Avatar asked Nov 20 '16 18:11

eyelash


People also ask

What does target link libraries do in CMake?

Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.


1 Answers

I have been looking to link with Rpcrt4.lib and this worked on windows

target_link_libraries(${"LIB_NAME"} rpcrt4.lib)
like image 62
Avadhesh Sharma Avatar answered Sep 28 '22 02:09

Avadhesh Sharma