AnsweredAssumed Answered

Why do MQX projects specify -nodefaultlibs and -nostdinc?

Question asked by Joe Seymour on Jan 5, 2017

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.



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?