Build with gcc, link with mbed

28 Oct 2010 . Edited: 28 Oct 2010

Hi,

I would like to compile my program offline (the toolchain uses scons, python and gcc) as a library which will be linked with the online compiler (for Ethernet class).

I succeed to build an arm-gcc crosscompiler with http://github.com/esden/summon-arm-toolchain and created a simple main.c

int getLed()
{
        static int i = 0;
        i = (i + 1)%16;
        return i;
}

If I compile it with

../sat/bin/arm-none-eabi-gcc -o getLed.o -c main.c

and import it as a file (library don't work) in the mbed compiler I obtain :

"Cannot link object getLed.o as its attributes are incompatible with the image attributes. (EL6242E)"

So it tries to link with my .o file => good point.

I fixed the error with --short-wchar :

../sat/bin/arm-none-eabi-gcc -o getLed.o -c main.c --short-wchar

But now, the online comiler says :

Undefined symbol getLed() (referred from main.cpp.cpp.LPC1768.o). (EL6218E)

The main.cpp file is :

#include "mbed.h"

BusOut leds(LED4,LED3,LED2,LED1);

int getLed();

int main() {
    while (1) {
        leds = getLed();
        wait(0.2);
    }
}

And the getLed.o file is available here : http://demo.ovh.net/fr/2630abdcc8996edb92f1f1e0995de472/

If anyone have an idea ... ?

28 Oct 2010

Try:

extern "C" int getLed();

28 Oct 2010

Ok, thanks :-)

I forgot c++ mangling ... :/

03 Nov 2010

Hi Thomas,

Do you know the gcc or linker flags to link a binary with short wchars? I've compiled everything in a project with short wchars (including the gcc and system libraries) and it still tries to link for a 4-byte wchar output (giving a bunch of warnings, but because everthing is infact 2-byte wchars, it works)... frustrating!

I'm trying to set up my build system for possible future linking against the mbed library.

Hugo

03 Nov 2010

For the moment I don't link :s

I just do a big .ar file from .o files.