CMake cannot find IMPORTED library

In foo/CMakeLists.txt, based on this and this , I have the following

SET (EXTERNAL_LIB_ROOT "../../external_libs/")

ADD_LIBRARY (avcodec-debug STATIC IMPORTED)

SET_PROPERTY (
    TARGET avcodec-debug PROPERTY IMPORTED_LOCATION
    ${EXTERNAL_LIB_ROOT}/libavcodec-0.8.10.a)

In bar/CMakeLists.txtI have this:

# old way uses system libraries
#TARGET_LINK_LIBRARIES (bar avformat avcodec avutil)

# new way uses local debug builds
TARGET_LINK_LIBRARIES (bar avformat avcodec-debug avutil)

When I run make, I get

/usr/bin/ld: cannot find -lavcodec-debug

If I go back to the old way, build, touch foo/CMakeLists.txtand rebuild, the CMake configuration output indicates that avcodec-debug is in the build system.

So why can't I add it as a dependency?

+4
source share
2 answers

, . , , ( ), CMakeLists.txt, ( , add_subdirectory() CMakeList).

foo bar , avcodec-debug bar/CMakeLists.txt, .

, , . ( ) foo/CMakeLists.txt foo/avcodec.cmake, CMakeList

add_subdirectory(foo)

include(foo/avcodec.cmake)
+5

Angew, , GLOBAL-. , add_library.

ADD_LIBRARY (avcodec-debug STATIC IMPORTED GLOBAL)

+4

Source: https://habr.com/ru/post/1539919/


All Articles