4 years, 5 months ago.

How do I find "all" MBED library sources.

For instance, serial_api.c. I see serial_api.h. I want to see how printf is hooked up to the USB port.

In Stream.h there's the following externs:

extern void mbed_set_unbuffered_stream(FILE *_file); extern int mbed_getc(FILE *_file); extern char* mbed_gets(char *s, int size, FILE *_file);

How can I see those routines? Why are they done as externs?

1 Answer

4 years, 5 months ago.

The source code is in the mbed-dev library.

You can replace the standard mbed library with that one and you'll (in theory) get the same end result but a longer compile time. You should only use the dev version if you need a bug fix that hasn't made it into the release version or need to change something in the library for some reason. In addition to making the compile time longer it's not been as well tested as the released version and so there is always a chance that something has been broken.

The functions are marked as externs so the compiler doesn't complain when it can't find them in the included .cpp files. The linker will then find them in the pre-compiled library and hook things together correctly.

Accepted Answer

Regarding the externs, usually .h files are used to supply definitions of externally defined functions and data, so why are externs used here? I haven't been able to find the functions given in the externs.

I've been to "mbed-dev library" and can't find everything. For instance, serial_api.c that I mentioned above ain't in there.

Thanks for your response. All of the responses I've gotten have been helpful.

posted by Alfred Hume 09 Mar 2016

You're not looking hard enough.

Since the underlying hardware is different for each platform the serial_api is different for each platform. Which means there isn't a single copy of serial_api.c, there are about 80 copies of it.

targets/hal/[vendor]/[target]/serial_api.c exists for every supported platform and CPU type.

posted by Andy A 09 Mar 2016

Wow! Didn't think of that. I'll find the one for my 1768. I have a get-to-the-bottom-of-things instinct. Maybe that'll explain the externs, but it does seem like the externs should be in some .h file.

posted by Alfred Hume 09 Mar 2016