I have a library with a C++ wrapper around auto-generated C code, built with CMake and gcc. When I compile it I get these warnings which I would like to inhibit:
src/ssp/autogenerated.c: In function ‘x1111’:
src/ssp/autogenerated.c:185:1: warning: implicit declaration of function ‘x1111’; did you mean ‘x1110’? [-Wimplicit-function-declaration]
185 | x1111();
| ^~~~~~~~~~
I should be able to inhibit these warnings with the -Wno-implicit-function-declaration
warning option. I add that to my CMakeLists.txt like so:
file(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/ssp/*.c src/ssp/*.cpp)
add_library(mylib SHARED ${SRCS})
target_compile_options(mylib PRIVATE "-Wno-implicit-function-declaration")
However, there is still a *.cpp
source in there and so compiling gives me:
cc1plus: error: command-line option ‘-Wno-implicit-function-declaration’ is valid for C/ObjC but not for C++ [-Werror]
cc1plus: all warnings being treated as errors
Is there a way inhibit these warnings? I'm imagining it might be possible to apply -Wno-implicit-function-declaration
to C sources only or to have it ignored by g++
?