Cmake 实践libhello 上。 5,为 target 添加共享库 我们现在需要完成的任务是将目标文件链接到 libhello,这里我们需要引入两个新的指令 LINK_DIRECTORIES 和 TARGET_LINK_LIBRARIES LINK_DIRECTORIES 的全部语法是: LINK_DIRECTORIES(directory1 directory2 ...) 这个指令非常简单,添加非标准的共享 这个指令非常简单,添加非标准的共享库搜索路径,比如,在工程内部同时存在共享库和可 执行二进制,在编译时就需要指定一下这些共享库的路径。这个例子中我们没有用到这个指 令。 TARGET_LINK_LIBRARIES 的全部语法是: TARGET_LINK_LIBRARIES(target library1library2 为了解决我们前面遇到的 HelloFunc 未定义错误,我们需要作的是向 src/CMakeLists.txt 中添加如下指令: TARGET_LINK_LIBRARIES(main hello) 也可以写成 TARGET_LINK_LIBRARIES(main libhello.so) 这里的 hello 指的是我们上一节构建的共享库 libhello. 进入 build 目录重新进行构建。 0 码力 | 47 页 | 264.27 KB | 1 年前3
C++高性能并行编程与优化 - 课件 - 16 现代 CMake 模块化项目管理指南biology : target_link_libraries(pybmain PUBLIC biology) • 由于 PUBLIC 属性具有传染性,根 /biology/include 现在也加入 pybmain 的 头文件搜索路径了,因此 pybmain 里可以 #include 到 biology 的头文件。 • 同理如果又有一个 target_link_libraries(zxxpig PUBLIC s(yourapp ${XXX_INCLUDE_DIRS}) • target_link_libraries(yourapp ${XXX_LIBRARIES}) • 现代(小彭老师推荐): • find_package(XXX REQUIRED COMPONENTS xxx) • target_link_libraries(yourapp XXX::xxx) 大多都能同时兼容现代和古代 cpp) • find_package(TBB CONFIG REQUIRED COMPONENTS tbb) • target_link_libraries(yourapp PUBLIC TBB::tbb) 古代 CMake 常见问题 1. target_link_libraries(yourapp ${XXX_LIBRARIES}) 2. target_include_directories(yourapp0 码力 | 56 页 | 6.87 MB | 1 年前3
Conan 1.4 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 4.2 Installing dependencies If you have a terminal with light colors 4.5 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 121 conan Documentation, Release 1.4.5 The conan_basic_setup() is0 码力 | 421 页 | 2.84 MB | 1 年前3
Conan 1.5 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 4.2 Installing dependencies If you have a terminal with light colors 5.2 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 422 页 | 2.85 MB | 1 年前3
Conan 1.6 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 3.2 Installing dependencies If you have a terminal with light colors 6.1 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 428 页 | 2.87 MB | 1 年前3
Conan 1.7 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 3.2 Installing Dependencies To improve visibility, if you have a terminal 7.4 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 433 页 | 2.95 MB | 1 年前3
Libraries: A First Step Toward Standard C++ Dependency Managementadd_library(SqrtLibrary STATIC mysqrt.cxx) target_link_libraries(MathFunctions PUBLIC SqrtLibrary) add_executable(Tutorial tutorial.cxx) target_link_libraries(Tutorial PUBLIC MathFunctions) % ninja -v part of the build find_package(bar REQUIRED) # external to the build add_executable(foo) target_link_libraries(foo bar) # makes no difference which bar # bar could be in this build or could be from find_package "Link to default component(s)." ON) if (USE_DEFAULT_COMPONENTS) target_link_libraries(demo spdlog) else() target_link_libraries(demo spdlog::spdlog) endif() 69Configure [0/1] Running CMake to regenerate0 码力 | 82 页 | 4.21 MB | 6 月前3
Conan 1.8 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(md5 md5.cpp) target_link_libraries(md5 ${CONAN_LIBS}) 8. Now we are ready to build and run our Encrypter app: (win) $ cmake 8.4 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 458 页 | 3.03 MB | 1 年前3
Conan 1.9 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(md5 md5.cpp) target_link_libraries(md5 ${CONAN_LIBS}) 8. Now we are ready to build and run our Encrypter app: (win) $ cmake 9.2 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 470 页 | 3.05 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 01 学 C++ 从 CMake 学起准备的参数可能对 MSVC 不适用。 • CMake 可以自动检测当前的编译器,需要添加哪些 flag 。比如 OpenMP ,只需要在 CMakeLists.txt 中指明 target_link_libraries(a.out OpenMP::OpenMP_CXX) 即可。 输出的可执行文件 输入的多个源文件 CMake 的命令行调用 • 读取当前目录的 CMakeLists.txt ,并在 环境下,初学者自己创建库时,建议使用静态库。 • 但是他人提供的库,大多是作为动态库的,我们之后会讨论如何使用他人的库。 • 创建库以后,要在某个可执行文件中使用该库,只需要: • target_link_libraries(myexec PUBLIC test) # 为 myexec 链接刚刚制作的库 libtest.a • 其中 PUBLIC 的含义稍后会说明( CMake 中有很多这样的大写修饰符) PRIVATE 对他们同理: • target_include_directories(myapp PUBLIC /usr/include/eigen3) # 添加头文件搜索目录 • target_link_libraries(myapp PUBLIC hellolib) # 添加要链接的库 • target_add_definitions(myapp0 码力 | 32 页 | 11.40 MB | 1 年前3
共 104 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11













