Skip to content

Instantly share code, notes, and snippets.

@chayanforyou
Created July 7, 2023 07:12
Show Gist options
  • Save chayanforyou/69e0063810a571deb2fbd0149e38a3af to your computer and use it in GitHub Desktop.
Save chayanforyou/69e0063810a571deb2fbd0149e38a3af to your computer and use it in GitHub Desktop.
Arduino not working with ".c" file

The .ino files of Arduino sketches are compiled as C++ after a little bit of preprocessing. If you want to use C functions in C++, you need to wrap their declarations in:

extern "C" {}

There are a couple ways you can do this:

In the sketch:

extern "C" {
#include "SomeCFunctions.h"
}

Or, in the .h file:

#ifdef __cplusplus
extern "C" {
#endif

// C function declarations here

#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment