2
votes

I wrote my own library for an Arduino Leonardo. It consists of some header files and all defined methods are implemented in *.c-files. When I compile it with Eclipse everything works fine, but the compiler of the Arduino IDE doesn't get the methods. It returns the error messages:

impl.cpp:20: undefined reference to initOptiCom()
impl.cpp:21: undefined reference to calc(unsigned char*, int)
impl.cpp:25: undefined reference to getInitSeq(unsigned char*, long*, long)
impl.cpp:32: undefined reference to decode(unsigned char*, long)
collect2: error: ld returned 1 exit status

All files can be found in the arduino library dir and all libraries are included... I searched for some examples that implement a C-library for arduino but I found just some for C++.

Maybe you know what's wrong here, I tried a lot but failed :(

1

1 Answers

3
votes

Perhaps it's just name mangling. Either declare the functions as extern "C", or compile them as C++ (rename the file to .cpp or pass the -x c++ flag to GCC when compiling).