Home > Blockchain >  How to disable specific compilation warnings from CPP compiler in VSCode? (preferably using build op
How to disable specific compilation warnings from CPP compiler in VSCode? (preferably using build op

Time:10-27

I am using VSCode and ESP-IDF to program Arduino. Some of the Arduino library files are generating warnings such as below.

988/1135] Building CXX object esp-idf/arduino/CMakeFiles/__idf_arduino.dir/libraries/WiFi/src/WiFiScan.cpp.obj
/Users/sr/projects/gcp-iot/components/arduino/libraries/WiFi/src/WiFiScan.cpp:45:21: warning: 'const char* cipher_str(int)' defined but not used [-Wunused-function]
 static const char * cipher_str(int cipher)
                     ^~~~~~~~~~
[1003/1135] Building CXX object esp-idf/arduino/CMakeFiles/__idf_arduino.dir/libraries/WiFi/src/WiFiGeneric.cpp.obj
/Users/sr/projects/gcp-iot/components/arduino/libraries/WiFi/src/WiFiGeneric.cpp:187:21: warning: 'const char* auth_mode_str(int)' defined but not used [-Wunused-function]
 static const char * auth_mode_str(int authmode)
                     ^~~~~~~~~~~~~
[1013/1135] Building CXX object esp-idf/arduino/CMakeFiles/__idf_arduino.dir/libraries/Wire/src/Wire.cpp.obj
/Users/sr/projects/gcp-iot/components/arduino/libraries/Wire/src/Wire.cpp: In member function 'uint8_t TwoWire::requestFrom(uint16_t, uint8_t, bool)':
/Users/sriraj/projects/gcp-iot/components/arduino/libraries/Wire/src/Wire.cpp:363:15: warning: variable 'err' set but not used [-Wunused-but-set-variable]
     esp_err_t err = ESP_OK;

I have tried setting -Wno-unused-function flag in various places but have failed to disable these warnings. Can someone please advise the right place to set this build option so I don't see these warnings. I am using VSCode on MacOS. Thank you in advance.

CodePudding user response:

Navigate to your ESP-IDF directory and look for build.cmake file under esp-idf/tools/cmake directory.

In the build.cmake file - look for the section called function(__build_set_default_build_specifications) - this contains all the default compiler options that are executed at build time. Include -Wno-unused-function here, save and recompile your project!

But be aware that this will disable this warning globally and affect other projects as well.

  • Related