Issue
I have a main.cpp
thus:
#include <stdio.h>
int main(){
#if defined(_LINDEBUG)
#if defined(VSCODE)
printf("VSCODE defined"\n);
#else
printf("VSCODE not defined\n");
#endif
#endif
}
My c_cpp_properties.json
file in .vscode/
folder is thus:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${default}"
],
"defines": ["VSCODE"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
]
}
I compile and link this via make
thus:
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
I expected VSCODE
to be defined via the .json
file. _LINDEBUG
is defined via the make
compilation as -D_LINDEBUG
. The net effect is that the output is:
VSCODE not defined
.
Is there a way to define some macros via c_cpp_properties.json
file instead of via the make
argument?
tasks.json
is:
{
"label": "lindbgbuild",
"type": "shell",
"command": "make",
"args": [
"CONF=Debug",
"-C",
"./.vscode"
],
"group": "build",
"problemMatcher": []
}
Makefile
exits in .vscode\
folder that calls Makefile-Debug.mk
that contains the actual g++ ...
commands.
Solution
Per the documentation [link]:
defines
A list of preprocessor definitions for the IntelliSense engine to use while parsing files. Optionally, use = to set a value, for example VERSION=1.
So, it seems that you would only add some defines there for the sake of helping out the Intellisense engine. Some quick testing could not get the defines from the c_cpp_properties.json file to be embedded into the code. My guess is that the option exists to help write code when you only have a portion of the project on your machine.
For what it's worth, you are not defining _LINDEBUG
via make. It is a compiler flag [link]. More specifically, it defines whatever name as a macro and gives it a value of 1. The documentation did not state where those definitions are placed.
If what you pasted are the contents of your makefile, you would be better served by learning to create a proper makefile, or take it up a level and learn to use a build tool like cmake.
EDIT: Per your comment, it would just be a matter of adding the arguments to your build task if you want VS Code to define them.
Answered By - sweenish Answer Checked By - Senaida (WPSolving Volunteer)