CMake项目构建外部库:
include(ExternalProject)
set(EXTLIBS_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/extlibs)
ExternalProject_Add(ext-somelib
URL https://github.com/.../archive/refs/tags/somelib.tar.gz
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${EXTLIBS_INSTALL_PREFIX}
-DCMAKE_PREFIX_PATH=${EXTLIBS_INSTALL_PREFIX}
)
include_directories(${EXTLIBS_INSTALL_PREFIX}/include)
add_executable(mainTarget ...)
add_dependencies(mainTarget ext-somelib)
target_link_directories(mainTarget ${EXTLIBS_INSTALL_PREFIX}/lib)
target_link_libraries(mainTarget somelib)
# (link <build>/extlibs/lib/libsomelib.so)
字符串
当配置项目时,它会失败并显示错误:
CMakeLists.txt中的CMake错误:#(target_link_directories):
使用无效参数调用target_link_directories
为使用ExternalProject构建的依赖项指定链接目录的正确方法是什么(因此在配置时还不可用)?
1条答案
按热度按时间vxf3dgd41#
在命令
target_link_directories
中,需要关键字PUBLIC、PRIVATE或INTERFACE之一。正确:
字符串