cmake无法链接可执行文件-LJSONCPP:没有使用github子模块的此类文件
我正在一个使用JSONCPP进行解析和CMAKE进行编译的项目。我添加了JSONCPP官方git repository 作为我的项目的子模型subpoule添加repo_url外部/jsoncpp ,以使每个依赖关系保持在一起。
运行cmake -b out/build
时,它正常工作。但是,当我做make
时,我会收到以下错误:
/usr/bin/ld:找不到-ljsoncpp:no这样的文件或目录
。
文件以下方式组织了:
- root
- out/build
- external
- jsoncpp (cloned repo)
- include
foo.h
bar.h
- src
foo.cpp
bar.cpp
main.cpp
CMakeLists.txt
cmakelists.txt是这样:
cmake_minimum_required(VERSION 3.22.1)
project(ants)
# ".cpp" files in folder "src" into cmake variable "SOURCE"
file(GLOB SOURCE "src/*.cpp")
# Executable
add_executable(${PROJECT_NAME} ${SOURCE})
# Directory where cmake will look for include files
include_directories(include)
# Tells cmake to compile jsoncpp
add_subdirectory(external/jsoncpp)
# Tells cmake where to look for jsoncpp include files
target_include_directories(${PROJECT_NAME}
PUBLIC external/jsoncpp/include
)
target_link_libraries(${PROJECT_NAME} jsoncpp)
I am working in a project which uses jsoncpp for parsing and cmake for compilation. I added the jsoncpp official git repository as a submodule to my project with git submodule add REPO_URL external/jsoncpp
, so as to keep every dependency together.
When running cmake -B out/build
, it works normally. But when I do make
, I get the following error:
/usr/bin/ld: cannot find -ljsoncpp: No such file or directory
.
The files are organized the following way:
- root
- out/build
- external
- jsoncpp (cloned repo)
- include
foo.h
bar.h
- src
foo.cpp
bar.cpp
main.cpp
CMakeLists.txt
The CMakeLists.txt is like this:
cmake_minimum_required(VERSION 3.22.1)
project(ants)
# ".cpp" files in folder "src" into cmake variable "SOURCE"
file(GLOB SOURCE "src/*.cpp")
# Executable
add_executable(${PROJECT_NAME} ${SOURCE})
# Directory where cmake will look for include files
include_directories(include)
# Tells cmake to compile jsoncpp
add_subdirectory(external/jsoncpp)
# Tells cmake where to look for jsoncpp include files
target_include_directories(${PROJECT_NAME}
PUBLIC external/jsoncpp/include
)
target_link_libraries(${PROJECT_NAME} jsoncpp)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jsoncppconfig.cmake
定义属性interface_include_directories
for targetsjsoncpp_lib
和JSONCPP_LIB_STATIC
。您需要查询目标属性并手动设置:
链接是通过:
源。
尝试以下操作:
The
jsoncppConfig.cmake
defines propertyINTERFACE_INCLUDE_DIRECTORIES
for targetsjsoncpp_lib
andjsoncpp_lib_static
.You need to query the target property and set it manually:
Linking is done via:
Source.
Try this: