Hello
I have a problem with compiling my project. I've created some debug configuration for my project in c_cpp_settings.json and there is a "__DEBUG" item in sections defines. But when I try to check it in my main.cpp file I see that no __DEBUG directive has been added (#else branch works):
extern "C" void app_main(void)
{
#ifdef __DEBUG
Target = TargetBase::CreateInstance(DEVICE_TYPE);
#else
Target = TargetBase::CreateInstance();
#endif
// Some code below
}
My c_cpp_settings.json:
{
"configurations": [
{
"name": "Debug",
"compilerPath": "C:\\esp\\tools\\xtensa-esp32-elf\\esp-2022r1-RC1-11.2.0\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"includePath": [
"${config:idf.espIdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"defines": [
"__DEBUG"
],
"browse": {
"path": [
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": false
},
"intelliSenseMode": "linux-gcc-x86",
"compilerArgs": []
},
],
"version": 4
}
What can I do for solving this problem?
idf.py build ignores defines in c_cpp_settings.json
Re: idf.py build ignores defines in c_cpp_settings.json
I've reproduced this problem with example project from Espressif-IDF plugin for VS Code:
1. Eviroment: Windows 10, Visual studio code v1.7.0, Espressif IDF plugin v1.5.0.
2. Create "Hello world" example project (View->Command Pallete->ESP-IDF: Show example projects->hellow_world)
3. In main.c replace string printf("Hello world!\n); with
#ifdef __DEBUG
printf("Hello world debug!\n");
#else
printf("Hello world!\n");
#endif
4. In c_cpp_settings.json add defines section into default configuration "ESP-IDF":
"defines": [
"__DEBUG"
]
5. Build and flash
Expected behavior: "Hello world debug!" printed. Fact: "Hello world!"
Does anybody have an idea? What's wrong?
1. Eviroment: Windows 10, Visual studio code v1.7.0, Espressif IDF plugin v1.5.0.
2. Create "Hello world" example project (View->Command Pallete->ESP-IDF: Show example projects->hellow_world)
3. In main.c replace string printf("Hello world!\n); with
#ifdef __DEBUG
printf("Hello world debug!\n");
#else
printf("Hello world!\n");
#endif
4. In c_cpp_settings.json add defines section into default configuration "ESP-IDF":
"defines": [
"__DEBUG"
]
5. Build and flash
Expected behavior: "Hello world debug!" printed. Fact: "Hello world!"
Does anybody have an idea? What's wrong?
Re: idf.py build ignores defines in c_cpp_settings.json
Hi Aleksei,
c_cpp_settings.json file only defines settings for code analysis (intellisense) for the MS C/C++ extension.
Build configuration used both by idf.py and IDF extension is determined by the project and component CMake files. If you need to add a compiler definition, you have to use CMake add_compile_definitions or target_compile_definitions functions.
c_cpp_settings.json file only defines settings for code analysis (intellisense) for the MS C/C++ extension.
Build configuration used both by idf.py and IDF extension is determined by the project and component CMake files. If you need to add a compiler definition, you have to use CMake add_compile_definitions or target_compile_definitions functions.
Re: idf.py build ignores defines in c_cpp_settings.json
Hello, ESP_igrr
Thank you for your answer. And one more question. I would like to have two configurations in VS Code - Release and Debug. My aim is to compile respective image when I switch between these configurations. So, my question is: how can I pass parameters to CMake from VSCode configuration? May I ask you to give an example?
Thank you for your answer. And one more question. I would like to have two configurations in VS Code - Release and Debug. My aim is to compile respective image when I switch between these configurations. So, my question is: how can I pass parameters to CMake from VSCode configuration? May I ask you to give an example?
Re: idf.py build ignores defines in c_cpp_settings.json
ESP-IDF project configuration is normally contained in sdkconfig file. This includes settings such as debug/release. In VS Code you can access these settings via the configuration editor, opened when you click on an sdkconfig file.
However it seems there is also a way to pass additional CMake variables to the build via the idf.cmakeCompilerArgs setting in VSCode. I think you can add a new CMake variable via this setting.
For example, you can add -DVAR=VALUE which will define a CMake variable VAR to the value "VALUE".
However it seems there is also a way to pass additional CMake variables to the build via the idf.cmakeCompilerArgs setting in VSCode. I think you can add a new CMake variable via this setting.
For example, you can add -DVAR=VALUE which will define a CMake variable VAR to the value "VALUE".
Re: idf.py build ignores defines in c_cpp_settings.json
Hi ESP_igrr! It seems to me that both of suggested variants are independ of configrations described in c_cpp_properties.json. But at least I can update sdkconfig and add desired define into it. In any case, thank you for your help!
Who is online
Users browsing this forum: No registered users and 51 guests