global visibility of functions etc.

19 Jun 2009

I am currently using the following

DigitalOut User_Led1(LED1);
AnalogIn AD0(15);
Serial pc(USBTX, USBRX);

and wish to use the same syntax in other modules of code. If i include these at the start of the code or in a header file the linker complains of multiple definitions. If i exclude them the the compiler complains that the the are not defined.

As i wish to use such lines as

  pc.printf("Welcome the the MBED Developers Module\n\r");

and

User_Led1 = LED_OFF;

in other C source modules, how do i go about doing this ?

 

 

 

19 Jun 2009

Hi Mike,

I am currently using the following

DigitalOut User_Led1(LED1);
AnalogIn AD0(15);
Serial pc(USBTX, USBRX);

and wish to use the same syntax in other modules of code. If i include these at the start of the code or in a header file the linker complains of multiple definitions. If i exclude them the the compiler complains that the the are not defined.

The key is to not get too caught up in the fact these are mbed Interfaces; it is just C/C++. So you just use the standard approach you would for any variable you'd want to use from multiple files.

So what you'll need to do is create the variables/objects in a source file, and define them as extern in a header file, which can be included by anyone who wants to use them.

I've written an example showing it:

http://mbed.co.uk/projects/cookbook/svn/examples/MultipleUsers

If in the compiler if you "Import Project" > "SVN" and use the above url, you should have a working example you can try/fiddle with yourself.

Does this solve your problem (or did I miss the point?!).

Thanks,
Simon

22 Jun 2009

thanks for this. I've created a global include for the I/O structure.

Best regards

David Giles