[英]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.