preprocessor directive visual studio code

Dig Kleppe
Posts: 28
Joined: Wed Jun 28, 2017 5:03 pm

preprocessor directive visual studio code

Postby Dig Kleppe » Sat Feb 28, 2026 10:56 am

I cannot get a global #define directive to work;
set in in c_cpp_properties.json

Code: Select all

  "configurations": [
    {
      "name": "ESP-IDF",
      "defines": [
        "TESTCASE"
      ],
      "compilerPath": "/home/dig/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc",
      "compileCommands": "${config:idf.buildPath}/compile_commands.json",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "browse": {
        "path": [
          "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
      },
      
    }
  ],
  "version": 4
}


in my code :

Code: Select all

#ifdef TESTCASE
    int cntr;
#endif
    
No cntr> (and no -DTESTCASE in compiler commandline). Please help.

Dig Kleppe
Posts: 28
Joined: Wed Jun 28, 2017 5:03 pm

Re: preprocessor directive visual studio code

Postby Dig Kleppe » Sat Feb 28, 2026 1:40 pm

took a while:
add line to base cmakeList.txt:

Code: Select all

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
set(PROJECT_VER "1.0.0.0")
project(${ProjectId})
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-DTESTCASE" APPEND)


Who is online

Users browsing this forum: Applebot, Baidu [Spider], Perplexity-User, PetalBot and 17 guests