【发布时间】:2021-02-04 14:03:59
【问题描述】:
我有一个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
}
我在.vscode/ 文件夹中的c_cpp_properties.json 文件是这样的:
{
"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
我希望通过.json 文件定义VSCODE。 _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\ 文件夹,该文件夹调用包含实际 g++ ... 命令的 Makefile-Debug.mk。
【问题讨论】:
标签: c++ ubuntu visual-studio-code