If you want to use a pre-built static library in your CMake, you can declare a STATIC IMPORTED CMake target:add_library(nanomsg STATIC IMPORTED)# Specify the nanomsg library's location and its include directories.set_target_properties(nanomsg PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/bin/lib/libnanomsg.a" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/bin/include")在这里,我们使用 CMAKE_CURRENT_LIST_DIR 变量以访问当前CMakeLists.txt文件所在的目录.Here, we use the CMAKE_CURRENT_LIST_DIR variable to access the directory in which the current CMakeLists.txt file resides. target_link_libraries() 用于将一个库链接到另一个库(或可执行文件),因此语法应至少包含两个参数.例如,如果要将静态 nanomsg 库链接到可执行文件(例如 MyExecutable ),则可以在CMake中执行以下操作:The target_link_libraries() is used to link one library to another library (or executable), so the syntax should include at least two arguments. For example, if you want to link the static nanomsg library to an executable (such as MyExecutable), you could do it in CMake like this:add_library(nanomsg STATIC IMPORTED)# Specify the nanomsg library's location and include directories.set_target_properties(nanomsg PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/bin/lib/libnanomsg.a" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/bin/include")# Define your executable CMake target.add_executable(MyExecutable main.cpp)# Link the nanomsg library to the executable target.target_link_libraries(MyExecutable PUBLIC nanomsg) 这篇关于将qmake转换为CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-25 17:17