'usbMIDI' was not declared

willvio

New member
I'm using CLION with PlatformIO plugin and following a tutorial which uses the `usbMIDI` module. I noticed in Arduino IDE, usbMID is recognized as it's in red, but when I compile my code with CLION, I got an "'usbMIDI' was not declared in this scope" error.

According to PlatformIO website I added `build_flags = -D USB_MIDI` to platformio.ini file. Build does pass after this and I was able to upload the code to the board. However, in CLION when I typed `usbMIDI.` hoping autocomplete show up, I got nothing. `usbMIDI` is still unrecognized by CLION and marked with "Use of undeclared identified 'usbMIDI'". I tried to figure out why this happen.

I searched `usbMIDI` in the whole project including libraries and could not find where usbMIDI is defined. From https://docs.platformio.org/en/latest/projectconf/section_env_build.html#projectconf-build-flags and https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html, I guess "-D USB_MIDI" might be a preprocessor option for the compiler, and the reason why the IDE doesn't know it is that I only configure the flag in the .ini file, not a project-wise. Referencing https://stackoverflow.com/questions/9017573/define-preprocessor-macro-through-cmake I added `add_compile_definitions(USB_MIDI)` to CMakeLists.txt, and still got nothing.

My questions are:

1. why the code can be compiled (recognized by the compiler) but not recognized by the IDE.
2. how does `build_flags = -D USB_MIDI` work? It seem to work only if added in the .ini file. Adding "add_compile_definitions(USB_MIDI)" to CMakeLists.txt, the code still cannot compile .
3. where can I find the definition for `usbMIDI`? I cannot find the documentation for it, only some examples in the teensyduino tutorial, and would like to know more details about the implementation.

My apologize if here is not the best place to ask these questions. I feel I have some misunderstanding in all these aspects, Arduino, Teensy, Clion, PlatformIO, CMake, build flags...
20211205134558.jpg
 
Back
Top