CMake imported library behaviour

18,100

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?

Share:
18,100

Related videos on Youtube

Antonio Petricca
Author by

Antonio Petricca

I'm writing software since I was 12th years old, on my Commodore 64, and now programming is my job! My top interests are cross platform development, low level programming, distributed computing, mobile development, frameworks design, backend high reliable processes designing and much more... I agree with Open Source tought, and I tend to publish, when possibile, my little and sometimes useful projects on SourceForge and CodeProject.

Updated on June 04, 2022

Comments

  • Antonio Petricca
    Antonio Petricca almost 2 years

    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!

    • User001
      User001 almost 6 years
      Hello, Please let me know how the issue was resolved. I followed the below comment, but it is leading to much more errors.
  • User001
    User001 almost 6 years
    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.
  • javs
    javs about 5 years
    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.
  • Kevin
    Kevin over 3 years
    Also, the path provided to IMPORTED_LOCATION must be a full path, not a relative one.
  • RAM
    RAM about 2 years
    It should be noted that cmake's doc on add_library has zero references to IMPORTED_IMPLIB.
  • Angew is no longer proud of SO
    Angew is no longer proud of SO about 2 years
    @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.
  • RAM
    RAM about 2 years
    @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.