Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
2 years, 9 months ago.
How can I factor mbed-os out of my (offline) project?
I'm working on creating a suite of mbed-os-based firmware images using an offline IDE. How can I build the mbed-os once, and link against it from multiple projects? That way I won't need to have another copy of the mbed-os source for each project, and build it for each.
Currently on Windows 10, I'm using mbed-cli to fetch code, and NXP MCUXpresso to build and debug. I'm open to using other tools, provided that I can debug on the target.
I've tried the following paths:
1. Used mbed-cli to import the mbed-os project, and exported it to mcuxpresso. I hoped to create a static library project that I could link other projects against, but the exporter creates an executable project. I don't think there are any mbed-cli exporter options to create a static library project instead of an executable, and there is no apparent way to convert an executable project to a static library project within MCUXpresso.
2. Used mbed-cli to import mbed-os, and to build mbed-os as a static library. I then also used mbed-cli to import the blinky example, exported to mcuxpresso. I tried to rip the mbed-os source out of that project and link against what I had built with mbed-cli, but it's not clear to me how to do this.
2 years, 8 months ago.
Will all of your projects use the same version of mbed OS with the same config files and same target? If so then you can compile the mbed-os library as a .lib and then use that in all your projects.
The way you do this is in 2 parts
Part 1 - compile mbed-os into a library
1) cd mbed-os
2) mbed compile
toolchain GCC_ARM target <TargetName> library
3) you now have a library file and associated header files in /BUILD/libraries/mbed-os/*, We will copy the entire mbed-os directory here in part 2
Part 2 - modify example code To use the compiled library generated in part 1 we need to modify the mbed-os directory. The Tools and targets.json need to be kept to enable the 'mbed compile' command. 1) keep the tools directory and the targets/targets.json file, everything else can be removed. 2) copy the mbed-os directory from part 1 to the root of your example project.
You should now be able to compile the example project and it will use the pre-built mbed-os library.
For reference Your project should look like this
/Example Project/ |_main.cpp |_mbed-os/ |_TargetName/GCC_ARM/* <- copied from Part 1 |_tools/* <- mbed tools |_targets/ |_targets.json <- config settings for target
All the best,