add_library(calculate_shared SHARED hello.cpp) #生成可以执行的文件 add_executable(main main.cpp) #连接共享库 target_link_libraries(main calculate_shared) 上面CmakeLists.txt里面, 共享库的名称是calculate_shared,这个是我们可以自己更改的
如果你的项目中有多个add_executable()命令,CMake将为每一个都生成一个独立的可执行文件。 2. add_subdirectory() add_subdirectory()是CMake中的一个命令,用于添加一个子目录到构建中。当此命令被执行时,CMake会进入指定的子目录,并查找并处理那个子目录下的CMakeLists.txt文件。 add_subdirectory(source_dir[...
add_executable(main)target_sources(main PUBLIC main.cpp) 多个.cpp源文件的情况 . ├── CMakeLists.txt├──main.cpp├── other.cpp└── other.h 使用target_sources直接添加 逐个添加即可: add_executable(main)target_sources(main PUBLIC main.cpp other.cpp) 通过设定变量,间接添加 使用变量来存储...
add_executable:添加可执行文件。 add_executable(targetName source1 source2 ...) add_library:添加库文件。 add_library(targetName source1 source2 ...) target_link_libraries:为目标添加链接库。 target_link_libraries(targetName lib1 lib2 ...) add_subdirectory:添加子目录。 add_subdirectory(source_d...
// myapp/CMakeLists.txt 文件CMAKE_MINIMUM_REQUIRED(VERSION3.5)PROJECT(myappVERSION1.0.0)# 头文件路径INCLUDE_DIRECTORIES(./include)# 库文件路径LINK_DIRECTORIES(./lib)# 源文件FILE(GLOBMYAPP_SRCS"*.c")# 编译目标ADD_EXECUTABLE(${PROJECT_NAME}${MYAPP_SRCS})# 依赖的动态库TARGET_LINK_LIBRARIES(...
CMakeLists.txt中. ADD_TEST指令的语法是: ADD_TEST(testname Exename arg1 arg2 ...) testname是自定义的test名称,Exename可以是构建的目标文件也可以是外部脚本等 等。后面连接传递给可执行文件的参数。如果没有在同一个CMakeLists.txt中打开 ENABLE_TESTING()指令,任何ADD_TEST都是无效的。
.├── CMakeLists.txt ├── main.cpp ├── other.cpp └── other.h 使用target_sources直接添加 逐个添加即可: add_executable(main) target_sources(main PUBLIC main.cpp other.cpp) 通过设定变量,间接添加 使用变量来存储: add_executable(main) set(sources main.cpp other.cpp) target_sources...
6. ADD_SUBDIRECTORY(utility) 添加要编译的子目录 为工程主目录下的存放源代码的子目录使用该命令,各子目录出现的顺序随意。 如上便是工程server_project 主目录src 下的CMakeLists.txt 文件,下一篇我们解释子目录utiltiy中的CMakeLists.txt 文件。 子目录utility 下的CMakeLists.txt 文件如下: ...
1. ADD_EXECUTABLE() #指定要生成的执行文件的名称server 其他用法同utilty/CMakeLists.txt 2. SET_TARGET_PROPERTIES 设置生成的执行文件存放的路径, 注意: 执行文件server 依赖的子目录utility 子目录生成的静态库libutility.a,在指定的时候要写成: TARGET_LINK_LIBRARIES(server utility) ...
请问cmakelists里 add_executable后面路径的格式应该是怎么样的?感谢! efool 2018-12-05 14:46:07 以cmakelist.txt 所在的路径为基础 donger205 2018-12-05 14:47:25 [quote][url=forum.php?mod=redirect&goto=findpost&pid=114255&ptid=54214]efool 发表于 2018-12-5 14:46[/url] 以cmakelist.txt...