Go Down

Topic: Custom cores question/problem (Read 453 times) previous topic - next topic

Drmn4ea

Hi,
I'm working on a custom Arduino-based board for low-power projects. As part of the effort I have added a handful of utility functions to the 'core' for power management. In the hope of creating as little mess as possible, I did it as follows:

* Created new files, mosquino.c/mosquino.h, containing the custom stuff (functions, and macros + prototypes respectively) in the custom core's directory (...My Documents\Arduino\hardware\Mosquino\cores\arduino\)
* #include "mosquino.h" from WProgram.h

Although macros defined in these files are 'visible' from the sketch, the functions are not... even if mosquino.h is #include'd into the sketch by hand:

Code: [Select]

core_test.cpp.o: In function `setup':
C:\DOCUME~1\Tim\LOCALS~1\Temp\build5515614687940556259.tmp/core_test.cpp:32: undefined reference to `power_full()'


A look in the build temp folder shows at least that a mosquino.c.o file was built and contains references to the function.

Currently using a core derived from 0022 and the 0022 IDE (haven't had time to patch it up to 1.0 yet).

Is this behavior expected? That is, is there some peculiarity/voodoo in the Arduino IDE's build process that causes this to fail, or am I missing something simple? (i.e have been away from c++ too long :p )?

Coding Badly


Two choices...

1. Change mosquino.c to mosquino.cpp (this is the choice I would take)

2. Wrap the definitions in mosquino.h with extern "C" { }

In other words, you have a C++ name mangling / linkage problem.

Drmn4ea

Thanks, that (option 1) solved it!

Out of curiosity, if all the functions contained there are vanilla C-style, is there any advantage/difference (e.g. in code size or performance, or other considerations) to one of these approaches over the other?


Coding Badly


In my opinion you are always better off using C++ (instead of extern/C).  The syntax is "tighter".  Many (most? all?) of the implicit type conversion problems are eliminated.  Name mangling alone is worth using C++ compilation.

I have not used straight-C in ... well ... let's say a few years and I have not once missed it.

Go Up