简体   繁体   English

如何使编译器版本特定于 ifdef?

[英]How can I make compiler version specific ifdef?

I've got the problem that my program will compile with g++10.2 and c++11 activated through cmake.我遇到的问题是我的程序将使用通过 cmake 激活的 g++10.2 和 c++11 进行编译。 but it will not compile with arduino dues arm-none-eabi-g++.exe compiler which also has c++11.但它不会用同样有 c++11 的 arduino 会费 arm-none-eabi-g++.exe 编译器编译。 The failure occurs because of one line that needs to be added for the arm compiler, but when I add that line to g++10.2 it won't compile.失败是因为需要为 arm 编译器添加一行,但是当我将该行添加到 g++10.2 时,它不会编译。

So I need an #ifdef or some alternative to activate and deactivate the line specific for the compiler.所以我需要一个#ifdef或一些替代方法来激活和停用特定于编译器的行。

Like Deumaudit said in the comments:就像 Deumaudit 在评论中所说的那样:

Try to use __arm__ , __aarch64__ or __ARM_ARCH macro尝试使用__arm____aarch64____ARM_ARCH

You'll probably be ok if you use #ifdef __arm__ or even #if defined(__arm__) || defined(__aarch64__)如果您使用#ifdef __arm__或什至#if defined(__arm__) || defined(__aarch64__) #if defined(__arm__) || defined(__aarch64__)

If you're planning to add more supported platforms to your program, it might be a good idea to define some macros when building for a specific platform.如果您计划向您的程序添加更多支持的平台,那么在为特定平台构建时定义一些宏可能是个好主意。 I have my own _MY_APP_ARM macro defined in my CMakeLists.txt:我在 CMakeLists.txt 中定义了自己的_MY_APP_ARM宏:

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
    add_definitions(-D_MY_APP_ARM)
endif()

Which I can then use as #ifdef _MY_APP_ARM然后我可以将其用作#ifdef _MY_APP_ARM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用特定的gcc编译器运行make命令? - How can I run make command by using specific gcc compiler? 如何使emacs对待#ifdef和#endif如'{'和'}'? - How do I make emacs treat #ifdef and #endif like '{' and '}'? 如何在 CMAKE 项目中更改 MSVC 编译器版本? - How can I change MSVC compiler version in a CMAKE project? 我可以将Visual Studio编译器设置为符合特定版本的c ++吗? - Can I set the Visual Studio compiler to conform to a specific version of c++? 使用#ifdef检测编译器 - Detect compiler with #ifdef 如何使 STL 的 C++ 编译器支持模板? - How can I make the C++ compiler support template for STL? 如何使编译器在C ++中创建默认构造函数? - How can I make the compiler create the default constructors in C++? 如何使编译器将特定代码“粘贴”到某个区域 - How to make the compiler 'paste' specific code to an area 如何使用 CMake 在特定构建配置中为特定目标设置特定编译器标志? - How can I set specific compiler flags for a specific target in a specific build configuration using CMake? 当#define 位于使用 dll 的可执行项目中时,如何检查 DLL 项目中的 #ifdef? - How can I check #ifdef in a DLL project, when the #define is in the executable project using the dll?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM