首页 > 解决方案 > 在 MacOS 上构建项目时,Cmake '无法在生成多个输出文件时指定 -o'

问题描述

我正在尝试在我的 Mac 上构建一个项目,我正在尝试移植一个程序。我正在使用 Cmake 编译和创建 Makefile 或 Xcode 项目。

如果我从构建目标子目录mkdir build && cd build && cmake ..makeclang: error: cannot specify -o when generating multiple output files

我也尝试过使用 G++-11,但我得到了类似的错误g++-11: fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files

我尝试通过使用禁用 Xcode 构建索引defaults write,并注释掉要包含的源中的头文件,以及将所有头文件移动到不同的目录。每次我得到同样的错误。

我有 Clang 12、G++ 11、Cmake 3.21.3 和 Make 3.81。这是项目https://github.com/CedarvilleCS/CedarLogic/blob/master/CMakeLists.txt的 GitHub 中的 make 文件。我很感激你们能给我的任何帮助,在此先谢谢你们。

编辑:cmake .. && make VERBOSE=1注释掉头文件后的输出(没有 Cmake 详细)

-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- 
-- import_library wx_widgets
-- wx_widgets is a header-only library.
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/arkinsolomon/Documents/CedarLogic/build
/usr/local/Cellar/cmake/3.21.3_1/bin/cmake -S/Users/arkinsolomon/Documents/CedarLogic -B/Users/arkinsolomon/Documents/CedarLogic/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.21.3_1/bin/cmake -E cmake_progress_start /Users/arkinsolomon/Documents/CedarLogic/build/CMakeFiles /Users/arkinsolomon/Documents/CedarLogic/build//CMakeFiles/progress.marks
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make  -f CMakeFiles/Makefile2 all
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make  -f CMakeFiles/CedarLogic.dir/build.make CMakeFiles/CedarLogic.dir/depend
cd /Users/arkinsolomon/Documents/CedarLogic/build && /usr/local/Cellar/cmake/3.21.3_1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/arkinsolomon/Documents/CedarLogic /Users/arkinsolomon/Documents/CedarLogic /Users/arkinsolomon/Documents/CedarLogic/build /Users/arkinsolomon/Documents/CedarLogic/build /Users/arkinsolomon/Documents/CedarLogic/build/CMakeFiles/CedarLogic.dir/DependInfo.cmake --color=
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make  -f CMakeFiles/CedarLogic.dir/build.make CMakeFiles/CedarLogic.dir/build
[  2%] Building CXX object CMakeFiles/CedarLogic.dir/src/version.cpp.o
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCEDARLOGIC_MAJOR=2 -DCEDARLOGIC_MINOR=3 -DCEDARLOGIC_PATCH=5 -DSTRICT -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_PRODUCTION_ -D__WXDEBUG__ -D__WXMSW__ -D__WX__ -I/Users/arkinsolomon/Documents/CedarLogic/include -I/Users/arkinsolomon/Documents/wxWidgets-3.0.5/include/msvc -I/Users/arkinsolomon/Documents/wxWidgets-3.0.5/contrib/include -isystem /Users/arkinsolomon/Documents/wxWidgets-3.0.5/include -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk /Users/arkinsolomon/Documents/wxWidgets-3.0.5/include/msvc/wx/setup.h /Users/arkinsolomon/Documents/wxWidgets-3.0.5/include/wx/wxprec.h -std=gnu++11 -MD -MT CMakeFiles/CedarLogic.dir/src/version.cpp.o -MF CMakeFiles/CedarLogic.dir/src/version.cpp.o.d -o CMakeFiles/CedarLogic.dir/src/version.cpp.o -c /Users/arkinsolomon/Documents/CedarLogic/src/version.cpp
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: cannot specify -o when generating multiple output files
make[2]: *** [CMakeFiles/CedarLogic.dir/src/version.cpp.o] Error 1
make[1]: *** [CMakeFiles/CedarLogic.dir/all] Error 2
make: *** [all] Error 2

此外,该项目在 Windows 上编译得很好,所以我认为这不是代码错误(虽然我没有尝试自己编译它)。

标签: c++cmakeg++gnu-makeclang++

解决方案


推荐阅读