Home > Software engineering >  cmake: target_link_libraries - /usr/bin/ld: cannot find X No such file or directory
cmake: target_link_libraries - /usr/bin/ld: cannot find X No such file or directory

Time:11-04

I'm trying to include this library in my project: https://github.com/kuafuwang/LspCpp.git

I'm using FetchContent which succesfully populates _deps/lspcpp-build, _deps/lspcpp-src, _deps/lspcpp-subbuild:

FetchContent_Declare(
    lspcpp
    GIT_REPOSITORY https://github.com/kuafuwang/LspCpp.git
)
FetchContent_GetProperties(lspcpp)
if(NOT lspcpp_POPULATED)
    FetchContent_Populate(lspcpp)
endif()

I define my executable:

add_executable(myApp
                foo.cpp
                bar.cpp
                ...
)

And try to link it:

target_include_directories(myApp lspcpp)
target_link_libraries(myApp lspcpp)

This produces this error:

/usr/bin/ld: cannot find -llspcpp: No such file or directory

CodePudding user response:

You are missing a step for FetchContent, to build the library.

FetchContent_Declare(
    lspcpp
    GIT_REPOSITORY https://github.com/kuafuwang/LspCpp.git
)
FetchContent_GetProperties(lspcpp)
if(NOT lspcpp_POPULATED)
    FetchContent_Populate(lspcpp)
    add_subdirectory(${lspcpp_SOURCE_DIR} ${lspcpp_BINARY_DIR}) # add this line
endif()
  • Related