"undefined reference" compiler error to a defined function

Arduino uses C++ for sketches and most libraries. Either use lib.cpp or conditionally add extern "C" in your header file, using this common pattern:

#ifdef __cplusplus
extern "C" {
#endif

// function declarations ...

#ifdef __cplusplus
} // extern "C"
#endif

This is because size_t happens to be an alias for unsigned int for this specific platform. The linker only sees the actual type, not its aliased name. (Note: on other platforms size_t might be an alias to a different type, so don't count on it being the same as unsigned int.)

1 Like