定义CLion分析仪的预处理器符号 [英] Defining preprocessor symbols for CLion analyzer
问题描述
在我的项目中,ifdef预处理程序指令中包含一个文件
In my project there's a file enclosed in an ifdef preprocessor directive
#ifdef SOME_SYMBOL
... entire file ...
#endif
SOME_SYMBOL由在此文件之前编译的另一个文件定义,并且代码按预期工作,但是静态分析器不知道此符号,因此它将SOME_SYMBOL视为未定义.整个文件没有突出显示语法,只是跳过了一些分析(例如突出显示语法错误).
SOME_SYMBOL is defined by another file that's compiled before this one, and the code works as expected, but the static analyzer isn't aware of this symbol and so it treats SOME_SYMBOL is undefined. The entire file has no syntax highlighting and some of the analysis is just skipped (e.g. syntax error highlighting).
是否有一种方法可以告诉分析器在不定义CMakeLists.txt的情况下将其视为已定义的符号?
Is there a way to tell the analyzer to treat this symbol as defined without defining it in CMakeLists.txt?
我没有选择在CMakeLists.txt中定义SOME_SYMBOL的选项,因为该项目依赖于某些编译路径中的未定义项目(更改此更改几乎是不可能的).
I don't have the option of defining SOME_SYMBOL in CMakeLists.txt since the project depends on it being undefined in some compilation paths (changing this would be near impossible).
更新:
似乎这是JetBrains当前的未解决问题.参见问题CPP-2286
Update:
Seems like this is currently an open issue with JetBrains. See Issue CPP-2286
推荐答案
Clion现在具有可用于检测IDE的宏: https://youtrack.jetbrains.com/issue/CPP-1296# comment = 27-1846360
Clion now has a macro which you can use to detect the IDE: https://youtrack.jetbrains.com/issue/CPP-1296#comment=27-1846360
#ifdef __JETBRAINS_IDE__
// Stuff that only clion will see goes here
#endif
这使您可以放入定义,以使在不足够聪明的情况下,clion可以正确渲染代码.
This allows you to put in defines to make clion render your code properly in cases where it can't be clever enough to figure it out.
__JETBRAINS_IDE__
宏的值是IDE的版本字符串.对于不同的Jetbrains IDE,存在特定版本的宏:__CLION_IDE__
,__STUDIO_IDE__
(对于Android Studio)和__APPCODE_IDE__
(对于AppCode).
The __JETBRAINS_IDE__
macro's value is a version string for the IDE. Specific versions of the macro exist for different Jetbrains IDEs: __CLION_IDE__
, __STUDIO_IDE__
(for Android Studio), and __APPCODE_IDE__
(for AppCode).
是的!
注意:在撰写本文时,仅在最新的CLion EAP中可用.
Note: At time of writing, this is only available in the latest CLion EAP.
这篇关于定义CLion分析仪的预处理器符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!