CMake混合编译C/C++与object-C

在C/C++与Objective-C混合编程时,使用CMake需要注意编译选项的设置。通过`add_compile_options(-x objective-c++)`确保OC代码正确编译,同时使用`set(CMAKE_EXE_LINKER_FLAGS "...")`指定链接器标志,如 `-framework Cocoa`等。遵循这些步骤,可以成功创建可执行文件。

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

        在cmake混合编译C/C++和object-C时,设置编译选项可以通过 add_compile_options或者 通过set命令修改 CMAKE_CXX_FLAGS CMAKE_C_FLAGS 。 
"D:\Sketchpad5.06\Sketchpad5\Evoker12345\Creation\c-c++\JetBrains CLion\CLion 2020.3.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\\编辑\C++\时间显示\工作区0 -- The C compiler identification is GNU 8.1.0 -- The CXX compiler identification is GNU 8.1.0 -- Check for working C compiler: D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/MinGW/mingw-18.0/MinGW/bin/gcc.exe -- Check for working C compiler: D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/MinGW/mingw-18.0/MinGW/bin/gcc.exe - broken CMake Error at D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/JetBrains CLion/CLion 2020.3.4/bin/cmake/win/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message): The C compiler "D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/MinGW/mingw-18.0/MinGW/bin/gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: D:/顏涱亼顏旑伋顏旑伨/缂栬緫/C++/鏃堕棿鏄剧ず/宸ヤ綔鍖�0/cmake-build-debug/CMakeFiles/CMakeTmp Run Build Command(s):D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/MinGW/mingw-18.0/MinGW/bin/mingw32-make.exe cmTC_37cc5/fast && D:/Sketchpad5.06/Sketchpad5/Evoker12345/Creation/c-c++/MinGW/mingw-18.0/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_37cc5.dir\build.make CMakeFiles/cmTC_37cc5.dir/build mingw32-make.exe[1]: Entering directory 'D:/顏涱亼顏旑伋顏旑伨/缂栬緫/C++/鏃堕棿鏄剧ず/宸ヤ綔鍖�0/cmake-build-debug/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_37cc5.dir/testCCompiler.c.obj D:\Sketchpad5.06\Sketchpad5\Evoker12345\Creation\c-c++\MinGW\mingw-18.0\MinGW\bin\gcc.exe -o CMakeFiles\cmTC_37cc5.dir\testCCompiler.c.obj -c D:\椤忔侗浜奸鏃戜紜椤忔棏浼╘缂傛牞绶玕C++\閺冨爼妫块弰鍓с仛\瀹搞儰缍旈崠?\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c gcc.exe: error: D:\椤忔侗浜奸鏃戜紜椤忔棏浼╘缂傛牞绶玕C++\閺冨爼妫块弰鍓с仛\瀹搞儰缍旈崠?\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c: No such file or directory gcc.exe: fatal error: no input files compilation terminated. mingw32-make.exe[1]: *** [CMakeFiles\cmTC_37cc5.dir\build.make:85: CMakeFiles/cmTC_37cc5.dir/testCCompiler.c.obj] Error 1 mingw32-make.exe[1]: Leaving directory 'D:/顏涱亼顏旑伋顏旑伨/缂栬緫/C++/鏃堕棿鏄剧ず/宸ヤ綔鍖�0/cmake-build-debug/CMakeFiles/CMakeTmp' mingw32-make.exe: *** [Makefile:140: cmTC_37cc5/fast] Error 2 CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project) -- Configuring incomplete, errors occurred! See also "D:/顏涱亼顏旑伋顏旑伨/缂栬緫/C++/鏃堕棿鏄剧ず/宸ヤ綔鍖�0/cmake-build-debug/CMakeFiles/CMakeOutput.log". See also "D:/顏涱亼顏旑伋顏旑伨/缂栬緫/C++/鏃堕棿鏄剧ず/宸ヤ綔鍖�0/cmake-build-debug/CMakeFiles/CMakeError.log". [Finished]帮我诊断一下,谢谢!
最新发布
06-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值