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
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++20 Modules: The Packaging and Binary Redistribution StoryThese days this is handled by build system abstractions and is hidden away from developers target_link_libraries(hello_world PRIVATE fmt::fmt)A typical library package “fmt” package ├── include │ └── set(CMAKE_CXX_EXTENSIONS OFF) find_package(fmt REQUIRED) add_executable(hello hello_world.cpp) target_link_libraries(hello PRIVATE fmt::fmt) CMakeLists.txt import fmt; int main() { fmt::print("Hello, world FetchContent_MakeAvailable(fmt) find_package(fmt REQUIRED) add_executable(hello hello_world.cpp) target_link_libraries(hello PRIVATE fmt::fmt) target_compile_options(hello PRIVATE "-std=c++23") [7/8] Building0 码力 | 76 页 | 2.09 MB | 6 月前3
Conan 1.10 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 10.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 码力 | 479 页 | 3.09 MB | 1 年前3
共 91 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10













