如何为C ++智能感知引擎定义宏? [英] How can I define macros for the C++ intellisense engine?
问题描述
使用"Default"
智能感知引擎时,我的C ++项目中的某些符号无法解析.事实证明,这是因为它们位于标头中,并由#ifdef
保护,而#ifdef
取决于makefile通过-D
标志传递给gcc的宏.我如何才能告诉智能感知引擎这些定义,以便它能够编译标头的那些部分?
When using the "Default"
intellisense engine, some of the symbols in my C++ project cannot be resolved. It turns out that it's because they are in headers where they are guarded by an #ifdef
that depends on a macro passed to gcc with the -D
flag by the makefile. How can I tell the intellisense engine about these defines so that it is able to compile those parts of the header?
推荐答案
项目生成文件defines
在.vscode/c_cpp_properties.json
中设置.
Project makefile defines
are set in .vscode/c_cpp_properties.json
.
"configurations": [
{
...
"defines":[
"MYSYMBOL",
"MYVALUE=1"
]
}
], ...
以下是一些打开c_cpp_properties.json
的方法:
Here are some methods to open c_cpp_properties.json
:
-
在诸如Intellisense无法解析的include语句之类的内容上找到绿色的花体.将鼠标悬停并单击出现的灯泡(它很小,需要单击一些游戏).它将在编辑器中打开项目配置文件.
Find a green squiggle on something like an include statement that Intellisense can't resolve. Hover around and click the lightbulb that appears (which is tiny and a bit of a game to click). It will open the project config file in the editor.
与上述相同,但将光标放在绿色的花体线条上,然后按Ctrl
+ .
.
Same as above, but put cursor on the green squiggle line and press Ctrl
+.
.
使用命令托盘:ctrl
+ shift
+ P
,然后选择C/C++: Edit configurations (JSON)
.
Use the command pallet: ctrl
+shift
+P
, then select C/C++: Edit configurations (JSON)
.
如果您的.vscode文件夹中已经存在该文件,请使用File
-> Open
打开它.
If the file already exists in your .vscode folder, open it with File
->Open
.
尽管在修改c_cpp_properties.json
之后,vscode将重新处理设置,但我发现在更改值时有时需要重新启动.
Although vscode will reprocess the settings after c_cpp_properties.json
is modified, I found a restart is sometimes required when changing values.
此处有基本且不完整的信息: https://code.visualstudio.com/docs/语言/cpp
There is basic and incomplete information here: https://code.visualstudio.com/docs/languages/cpp
这是有关c_cpp_properties.json
文件本身的良好链接: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
This is a good link about the c_cpp_properties.json
file itself: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
这篇关于如何为C ++智能感知引擎定义宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!