CMake imported library behaviour

2019-02-08 13:55发布

问题:

I've a strange problem with CMake.

I'm importing Curl into my project, so I write for you a simplified summary of my CMakeLists.txt file.

ADD_LIBRARY (libcurl SHARED IMPORTED)

SET_PROPERTY(TARGET libcurl PROPERTY IMPORTED_LOCATION ../lib/libcurl.lib)

When I run CMake it generates the project files for MS VC++ (also for Linux). Then into the project file I find a wrong reference to curl library (libcurl-NOTFOUND)!

If I change my code into static import:

ADD_LIBRARY (libcurl STATIC IMPORTED)

SET_PROPERTY(TARGET libcurl PROPERTY IMPORTED_LOCATION ../lib/libcurl.lib)

I find the right reference to ../lib/libcurl.lib.

Do you have any idea why this happens?

Thank you very much!

回答1:

For a shared library, the IMPORTED_LOCATION must point to the DLL, not the import lib. See the documentation. You might also want to set the IMPORTED_IMPLIB property.

BTW, CMake also has a find package for Curl; perhaps you could use that?



标签: c++ c cmake