19

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
  • Hello, Please let me know how the issue was resolved. I followed the below comment, but it is leading to much more errors. Commented May 28, 2018 at 13:10

1 Answer 1

21

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 module for Curl; perhaps you could use that?

Sign up to request clarification or add additional context in comments.

6 Comments

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.
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.
Also, the path provided to IMPORTED_LOCATION must be a full path, not a relative one.
It should be noted that cmake's doc on add_library has zero references to IMPORTED_IMPLIB.
@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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.