Pages: [1]   Go Down
Author Topic: Linking a Sketch against an external Library  (Read 542 times)
0 Members and 1 Guest are viewing this topic.
New Zealand
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Help!
« Last Edit: February 10, 2009, 02:18:33 am by kiwi64ajs » Logged


Cheers
Alex Shepherd

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

New Zealand
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad

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

ENTER_CRITICAL_SECTION
LEAVE_CRITICAL_SECTION

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... smiley-sad

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.

Comments?
Logged


Cheers
Alex Shepherd

New Zealand
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 11, 2009, 05:09:25 am by kiwi64ajs » Logged


Cheers
Alex Shepherd

Pages: [1]   Go Up
Jump to: