Forcing compiler to use CPP mode

I’m using Geekfactory Shell Library (GitHub - geekfactory/Shell: GeekFactory Shell Library - Library to create a simple Command Line Interface (CLI)., PlatformIO Registry).

Its sources are in C file (Shell.c). And I’m getting the following errors when building my project:

In file included from C:\users\fgka\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/wirish.h:58:0,
                 from C:\users\fgka\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/Arduino.h:30,
                 from .pio\libdeps\sam_v1\GeekFactory Shell Library_ID1946\Shell.h:31,
                 from .pio\libdeps\sam_v1\GeekFactory Shell Library_ID1946\Shell.c:20:
C:\users\fgka\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/ext_interrupts.h:90:6: error: conflicting types for 'attachInterrupt'
 void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg,
      ^~~~~~~~~~~~~~~
C:\users\fgka\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/ext_interrupts.h:69:6: note: previous declaration of 'attachInterrupt' was here
 void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode);
      ^~~~~~~~~~~~~~~

As you can see, the compiler does not understand function overloading in C mode.
If I rename the file to Shell.cpp, the problem goes away.
Should I open an issue against the library, or the compiler can be forced to compile in CPP mode?

Doesn’t exist anyway, two functions which have the same name will have the same symbol name and therefore a conflict.

Seems like the library is not expecting an Arduino.h implementation which is not usable in C code. Should be tackled in the library. It would be really dirty to hack in a switch of compilers for a single file, so I’d recommend using a forked version of the lib via github or simply putting the fixed version in lib/.

1 Like