Go Down

Topic: Linking a Sketch against an external Library (Read 992 times) previous topic - next topic

Alex Shepherd

Feb 10, 2009, 08:18 am Last Edit: Feb 10, 2009, 08:18 am by kiwi64ajs Reason: 1
Hi Guys,

I have a AVR archive library file libcan.a that has a can.h header file that defines all the functions in the libcan.a achive but I can't find a way to have the Arduino IDE compile and link process link against the libcan.a file.

How can I do this? Is there some magic directory I can put this file to have it included in the libraries link path?

The reason I'm having to try and link against the libcan.a file is that I tried creating an arduino library and put all the source files in a utility directory unde the library directory but it had lots of compile errors complaining about C99 compatibility issues... <sigh!>

So I gave up and thought I would try this way but have hit another road-block.


Alex Shepherd


The Arduino environment (IDE) doesn't currently support .a files.  There's a Makefile in hardware/cores/arduino that you should be able to modify to link in the .a file.

Alex Shepherd

Hmmm... I tried this but it seems that the makefile is not called from within the Arduino IDE, rather it is for when you want to build from the command line.

I was hoping for a solution that would work for building within the IDE :(

An alternative is to be able to compile the source code in the Arduino IDE as a library. However it is using:


from: #include <util/atomic.h>

which I think requires -std=c99 or -std=gnu99 to compile correctly. However the IDE does not include this flag... :(

Perhaps it would be useful if we could have some settings in the preferences file to add C and C++ compiler and linker flags so that we can modify the default behaviour without a rebuild of the IDE.


Alex Shepherd

Alex Shepherd

Feb 11, 2009, 11:08 am Last Edit: Feb 11, 2009, 11:09 am by kiwi64ajs Reason: 1
Hi Guys,

What I ended up doing was to download the whole Arduino build source code from the GoogleCode project as well as CygWin, found where the CFLAGS options were built in the code and simply added the -std=gnu99 option for both the C and CPP sections, rebuilt the IDE and then the library code in question compiled cleanly.

Now my little CAN2USB adaptor sketch working!!!

So maybe added some user specified CFLAGS for C and CPP as well LDFLAGS properties to the preferences.txt file might be useful.

Alex Shepherd

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131