gpt4 book ai didi

c++ - VSCode C++ c_cpp_properties.json "defines"没有在ubuntu上定义符号

转载 作者:行者123 更新时间:2023-12-04 19:07:53 26 4
gpt4 key购买 nike

我有一个 main.cpp因此:

#include <stdio.h>

int main(){
#if defined(_LINDEBUG)
#if defined(VSCODE)
printf("VSCODE defined"\n);
#else
printf("VSCODE not defined\n");
#endif
#endif
}
我的 c_cpp_properties.json文件在 .vscode/文件夹是这样的:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${default}"
],
"defines": ["VSCODE"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
}
我通过 make 编译和链接它因此:
g++ -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp   -c -g -D_LINDEBUG -std=c++14 -MMD -MP -MF "build/Debug/GNU-Linux/_ext/511e4115/main.o.d" -o build/Debug/GNU-Linux/_ext/511e4115/main.o ../src/main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -o dist/Debug/GNU-Linux/linux build/Debug/GNU-Linux/_ext/511e4115/main.o -lm -lpthread -ldl
我期待 VSCODE通过 .json 定义文件。 _LINDEBUG通过 make 定义编译为 -D_LINDEBUG .最终效果是输出为: VSCODE not defined .
有没有办法通过 c_cpp_properties.json 定义一些宏?文件而不是通过 make争论?
tasks.json是:
{
"label": "lindbgbuild",
"type": "shell",
"command": "make",
"args": [
"CONF=Debug",
"-C",
"./.vscode"
],
"group": "build",
"problemMatcher": []
}
Makefile退出 .vscode\调用 Makefile-Debug.mk 的文件夹包含实际的 g++ ...命令。

最佳答案

根据文档 [link] :

defines A list of preprocessor definitions for the IntelliSense engineto use while parsing files. Optionally, use = to set a value, forexample VERSION=1.


因此,您似乎只会在此处添加一些定义以帮助 Intellisense 引擎。一些快速测试无法从 c_cpp_properties.json 文件中获取要嵌入到代码中的定义。我的猜测是,当您的机器上只有一部分项目时,存在帮助编写代码的选项。
对于它的值(value),你没有定义 _LINDEBUG通过制作。它是一个编译器标志 [link] .更具体地说,它将任何名称定义为宏并赋予其值 1。文档没有说明这些定义的放置位置。
如果你粘贴的是你的makefile的内容,你最好学习创建一个合适的makefile,或者把它提高一个层次,学习使用像cmake这样的构建工具。
编辑:根据您的评论,如果您希望 VS Code 定义它们,只需将参数添加到您的构建任务中即可。

关于c++ - VSCode C++ c_cpp_properties.json "defines"没有在ubuntu上定义符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64467261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com