Cmake 多个 target 在一个 protect 下

本文介绍了一个使用CMake进行多模块项目配置的例子。其中包括两个主要的可执行模块project1和project2,每个模块都有其自己的CMakeLists.txt文件来定义构建规则。此配置展示了如何在CMake中设置基本项目结构并添加子目录来包含额外的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文件目录结构如下

.
├── CmakeLists.txt
├── main.cpp
└── target2
    ├── CmakeLists.txt
    └── main.cpp

第一个 CmakeLists.txt

cmake_minimum_required(VERSION 3.11)

Project(CmakeTest)
aux_source_directory(. src)
add_executable(project1 ${src})
add_subdirectory(target2)

第二个

aux_source_directory(. src)
add_executable(project2 ${src})

两个main 源文件就随便写 cout 输出 就行

Detecting C compiler ABI info failed to compile with the following output: Change Dir: D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp Run Build Command(s):D:\Android\Cmake\cmake-3.22.2-windows-x86_64\bin\ninja cmTC_cec21 && [1/2] Building C object CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o FAILED: CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o D:\Android\AndroidNDK\android-ndk-r21e-windows-x86_64\android-ndk-r21e\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -fPIE -v -MD -MT CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o -MF CMakeFiles\cmTC_cec21.dir\CMakeCCompilerABI.c.o.d -o CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o -c D:/Android/Cmake/cmake-3.22.2-windows-x86_64/share/cmake-3.22/Modules/CMakeCCompilerABI.c ninja: build stopped: subcommand failed. Determining if the C compiler works failed with the following output: Change Dir: D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp Run Build Command(s):D:\Android\Cmake\cmake-3.22.2-windows-x86_64\bin\ninja cmTC_9ef40 && [1/2] Building C object CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o FAILED: CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o D:\Android\AndroidNDK\android-ndk-r21e-windows-x86_64\android-ndk-r21e\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fPIE -MD -MT CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o -MF CMakeFiles\cmTC_9ef40.dir\testCCompiler.c.o.d -o CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o -c D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp/testCCompiler.c ninja: build stopped: subcommand failed.这个错误是怎么回事
最新发布
08-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值