[英]MacOs: How to change the C++ compiler and stdlib
I have a C++ project with CMake (and conan) and I want to switch the compiler to GCC-10, and its corresponding stdlibc++.我有一个带有 CMake(和 conan)的 C++ 项目,我想将编译器切换到 GCC-10 及其相应的 stdlibc++。 How do I do this on MacOS (Big Sur).
我如何在 MacOS (Big Sur) 上执行此操作。
Specifying -DCMAKE_CXX_COMPILER= which g++-10
in the cmake configure command successfully makes the switch to the g++ 10 compiler that I have on my system (installed with brew).在 cmake configure 命令中指定 -DCMAKE_CXX_COMPILER=
which g++-10
成功地切换到我的系统上的 g++ 10 编译器(与 brew 一起安装)。 However, I do not see any indicator that the includes and the stdlib are changed.但是,我没有看到任何指示包含和 stdlib 已更改。
My buidld command looks like:我的 buidld 命令看起来像:
/usr/local/bin/g++-10 -DCONCORE_USE_GLM=1 -DCONCORE_USE_OPENMP=1 -DCONCORE_USE_TBB=1 -DRC_USE_RTTI -I../test/. -I../test/../include -I../include -isystem /usr/local/Cellar/tbb/2020_U3/include -isystem /Users/lucteo/.conan/data/Catch2/2.11.0/catchorg/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/lucteo/.conan/data/rapidcheck/20200131/_/_/package/d2dbafdccc1ddd834eb76a31bdfdc6cc51e23ec1/include -fsanitize=address -fsanitize=undefined -D_GLIBCXX_USE_CXX11_ABI=1 -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wall -std=gnu++17 -MD -MT test/CMakeFiles/test.concore.dir/func/test_serializers.cpp.o -MF test/CMakeFiles/test.concore.dir/func/test_serializers.cpp.o.d -o test/CMakeFiles/test.concore.dir/func/test_serializers.cpp.o -c ../test/func/test_serializers.cpp
What is the best way to switch the compiler and stdlib?切换编译器和 stdlib 的最佳方法是什么?
To change stdlib you need to provide the -stdlib=stdlibc++
flag to the compiler in order to activate stdlibc++.要更改 stdlib,您需要向编译器提供
-stdlib=stdlibc++
标志以激活 stdlibc++。 This can be done through ccmake (turn on advanced mode (with t), and set CMAKE_CXX_FLAGS
to -stdlib=stdlibc++
), or through an equivalent directive in your CMakeLists.txt:这可以通过 ccmake(打开高级模式(使用 t),并将
CMAKE_CXX_FLAGS
设置为-stdlib=stdlibc++
)或通过 CMakeLists.txt 中的等效指令来完成:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=stdlibc++")
You also may need set(CMAKE_EXE_LINKER_FLAGS "-stdlib=stdlibc++")
:您可能还需要
set(CMAKE_EXE_LINKER_FLAGS "-stdlib=stdlibc++")
:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=stdlibc++")
To update your conan profile (say default
) use the command as follows:要更新您的柯南配置文件(例如
default
),请使用以下命令:
conan profile update settings.compiler.libcxx=stdlibc++ default
Note: -stdlib
is a Clang flag and will not work with any version of GCC ever released.注意:
-stdlib
是一个 Clang 标志,不适用于任何已发布的 GCC 版本。 GCC always uses libstdc++
unless you tell it to use no standard library at all with the -nostdlib
option (in which case you either need to avoid using any standard library features, or use -I
and -L
and -l
flags to point it to an alternative set of header and library files). GCC 总是使用
libstdc++
除非您通过-nostdlib
选项告诉它根本不使用标准库(在这种情况下,您要么需要避免使用任何标准库功能,要么使用-I
和-L
和-l
标志将其指向一组替代的头文件和库文件)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.