0

I'm using vscode to read a relatively large embedded project, but it seems that vscode doesn't recognize macros defined with cflags += -D in the makefile (as shown in the image below). I'm desperate to know how to get vscode to recognize macros defined in this way, or if it's possible to export macros defined in cflags to a file at compile time? If these can't be done, is there any other editor suitable for viewing embedded projects?

Here is an example of a macro in a makefile:

AIR_MULTI_POINT_ENABLE = y

ifeq ($(AIR_MULTI_POINT_ENABLE),y)
CFLAGS += -DAIR_MULTI_POINT_ENABLE
endif

vscode does not recognize this macro, and the corresponding code block is not colored.

enter image description here

enter image description here

enter image description here

rioV8
  • 24,506
  • 3
  • 32
  • 49
bear x
  • 1
  • Please [don't show images of text](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). Also please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And please learn how to [edit] your questions to improve them. – Some programmer dude Sep 26 '22 at 12:31
  • this is all depending on the language extension, it has nothing to do with VSC core – rioV8 Sep 26 '22 at 12:37
  • A _real_ IDE has options to define macros. Did you look for such? – the busybee Sep 26 '22 at 12:40
  • which 'c' compiler do you use? '-D' works for gcc or clang. '/D' for mircrosoft, .... Check compiler documentation. – Serge Sep 26 '22 at 12:52
  • @Serge I think what he wants is the editor to have visibility of the macros so that it will not assume the conditionally compiled block is inactive and "grey it out". The compiler will have no issue with it. – Clifford Sep 26 '22 at 14:57
  • The method of generating compile_commands.json doesn't work for my project. Fortunately, a colleague of mine taught me the output method of gcc compile macro definitions, I just need to define these macros in c_cpp_properties.json. – bear x Sep 27 '22 at 02:10
  • Use make -C to select the corresponding makefile file for execution, then output the execution parameters of GCC to the text file, and finally use the grep command to filter out the macros defined by cflag -D – bear x Sep 27 '22 at 02:14

0 Answers0