我希望 MacOS 中的 Clion 使用 g++-11 而不是 Clang 进行编译。当我设置工具链时,它没有通过测试。 Clion 给出“测试 Cmake 运行已完成,但出现错误”。这是屏幕截图 屏幕截图
我可以点击“更多”来检查错误。
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/bin/gcc-11
-- Check for working C compiler: /usr/local/bin/gcc-11 - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/x64/share/cmake-3.27/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"/usr/local/bin/gcc-11"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/private/var/folders/lf/x7t4ln495yx9rlng8jr8yk580000gn/T/cmake_check_environment1/_build7996487480848918631/CMakeFiles/CMakeScratch/TryCompile-Fl9cKx'
Run Build Command(s): /Applications/CLion.app/Contents/bin/ninja/mac/x64/ninja -v cmTC_8f62f
[1/2] /usr/local/bin/gcc-11 -o CMakeFiles/cmTC_8f62f.dir/testCCompiler.c.o -c /private/var/folders/lf/x7t4ln495yx9rlng8jr8yk580000gn/T/cmake_check_environment1/_build7996487480848918631/CMakeFiles/CMakeScratch/TryCompile-Fl9cKx/testCCompiler.c
FAILED: CMakeFiles/cmTC_8f62f.dir/testCCompiler.c.o
/usr/local/bin/gcc-11 -o CMakeFiles/cmTC_8f62f.dir/testCCompiler.c.o -c /private/var/folders/lf/x7t4ln495yx9rlng8jr8yk580000gn/T/cmake_check_environment1/_build7996487480848918631/CMakeFiles/CMakeScratch/TryCompile-Fl9cKx/testCCompiler.c
clang (LLVM option parsing): Unknown command line argument '-x86-pad-for-align=false'. Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '--x86-slh-loads=false'?
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
Error code: 1
看起来测试运行时使用了一些 clang 参数?
ChatGPT 提示可能是环境变量路径的问题,但在我看来没问题。以下是有关 PATH 的命令行输出:
(base) myname@mynames-MacBook-Pro bin % which gcc
/usr/bin/gcc
(base) myname@mynames-MacBook-Pro bin % which gcc-11
/usr/local/bin/gcc-11
(base) myname@mynames-MacBook-Pro bin % which gcc-14
/usr/local/bin/gcc-14
(base) myname@mynames-MacBook-Pro bin % echo $PATH
/Users/myname/anaconda3/bin:/Users/myname/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myname/Library/Python/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin
有谁知道如何解决这个问题。
这是我的 mac 上的 gcc 版本信息
(base) myname@myname-MacBook-Pro bin % gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.21)
Target: x86_64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
(base) myname@myname-MacBook-Pro bin % gcc-11 --version
gcc-11 (Homebrew GCC 11.4.0) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
(base) myname@myname-MacBook-Pro bin % gcc-14 --version
gcc-14 (Homebrew GCC 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
不要使用 gcc-11,这是 Apple clang 12 的别名。卸载 gcc-11
brew remove gcc-11
并使用 gcc-14,尽管如果可以使用 Apple clang 就没有多大意义。我敢打赌您在支持 C++11 或更高版本时遇到问题,那么只需在 CLion 中设置更新的标准即可。