18

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!

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • Hello, Please let me know how the issue was resolved. I followed the below comment, but it is leading to much more errors. – User001 May 28 '18 at 13:10

1 Answers1

20

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?

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
  • 1
    I have added the DLL to the IMPORTED_LOCATION.Also added the LIB with IMPORTED_IMPLIB But that is not resolving the error for the shared library linking. – User001 May 28 '18 at 13:11
  • cmake will also need to see IMPORTED_IMPLIB if you claim your library is 'SHARED' in add_library. Common practice in Find*.cmake modules seems to be to declare it 'UNKNOWN' to avoid the issue. – javs Mar 25 '19 at 21:30
  • Also, the *path* provided to `IMPORTED_LOCATION` must be a **full** path, not a relative one. – Kevin Aug 12 '20 at 13:15
  • It should be noted that cmake's doc on [add_library](https://cmake.org/cmake/help/v3.0/command/add_library.html) has zero references to `IMPORTED_IMPLIB`. – RAM Mar 08 '22 at 11:39
  • @RAM Zero references by full name. It does however tell you to look at *all* the `IMPORTED_*` properties for configuring the target, and just mentions the most important one (and it does say it must point to the *main* library file). Note that `IMPORTED_IMPLIB` is platform-specific, just like e.g. `IMPORTED_SONAME`. All the other `IMPORTED_*` properties may or may not be relevant, based on a given use case. It makes more sense for the docs to just point you to them all (as they do) instead of mentioning them all individually. – Angew is no longer proud of SO Mar 21 '22 at 07:43
  • @AngewisnolongerproudofSO mentioning IMPORTED_* means nothing as represent about two dozen different vars, some of which are irrelevant. It also doesn't sound right to downplay support for Windows libraries as "platform-specific" because all libs are platform specific and Windows is one of the most popular target platforms, if not the most popular. – RAM Mar 21 '22 at 18:12