Why do MQX projects specify -nodefaultlibs and -nostdinc?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why do MQX projects specify -nodefaultlibs and -nostdinc?

905 Views
joeseymour
Contributor III

MQX includes project files for several IDEs, including Kinetis Design Studio (KDS). It is relatively simple to replace the GNU toolchain in KDS with another (similar) GNU toolchain. Understandably, some minor adjustments might be required to make a project build correctly with the new toolchain, but the MQX projects seem to be particularly dependent on the directory layout used in KDS. My question is whether that is necessary? I'm using version 4.2 of MQX.

I'm referring to the use of -nodefaultlibs and -nostdinc combined with the explicit specification of paths to the standard headers and libraries that ship with the toolchain.

kds_preprocessor_settings.pngkds_include_paths.pngkds_linker_general.pngkds_linker_misc.png

Unless -nodefaultlibs and -nostdinc are specified, GCC will automatically look in the relevant directories for includes and libraries. As far as I can tell, passing -nodefaultlibs and -nostdinc and then explicitly adding these default include/library paths again has almost no impact on the behaviour of GCC, compared to its default behaviour.

I say almost, because it has two crucial impacts:

  • If you try and build that project with a different GNU toolchain, which uses a different directory layout, then the project won't build because it explicitly specifies the directory layout used in the KDS toolchain, instead of letting GCC just do the right thing.
  • GCC has a multilib mechanism. It ships with multiple builds of the same libraries, each built with different sets of options. This is useful because some sets of options are incompatible with each other or with some hardware. GCC will then choose which libraries to link against, based on the options that you pass. For example, if you are building for a Cortex-M0 then GCC might use libraries built for a Cortex-M0, while if you are building for a Cortex-M4 then GCC might use libraries built for a Cortex-M4 which will be able to take advantages of features not available on a Cortex-M0. By passing -nodefaultlibs and then explicitly specifying the library paths, the project is effectively disabling this multilib mechanism. If you change a compiler flag, then you need to remember to check whether or not there is a more appropriate multilib for your new set of options, and manually update the library paths if appropriate.

Based on this, I'm asserting that the purpose of the -nodefaultlibs and -nostdinc options is to allow users to completely disable the includes and libraries that ship with the GNU toolchain, and replace them with another set of includes/libraries in a different location. To use these options and then specify the same set of includes/libraries that they've just disabled seems bizarre. My question is: why are the MQX projects set up in this manner?

2 Replies

662 Views
soledad
NXP Employee
NXP Employee

Hi Joe,

 

MQX RTOS contains its own STDIO libraries and ignores the GCC libraries. This is because MQX RTOS is

thread-safe.This ensures all library code will run correctly during simultaneous execution by multiple threads. All processes can access shared data and multiple instances of library functions without the risk of undefined behaviour.

 

I hope this helps,


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

662 Views
joeseymour
Contributor III

Hi Sol,

Thanks for the reply, but it doesn't really answer my question:

Why do the KDS MQX projects seem to be setup to ignore the GCC libraries (as you say), but then add them back again in a less portable way (as explicit include and library paths). In essence the projects don't seem to ignore the libraries?

Thanks,

Joe