Simple Use of GCC to Compile C Files in Keil Projects

It must be said that Keil seems to be the most widely used IDE among domestic users. After being acquired by ARM, the introduction of the Keil MDK development environment with ARMCC and other compilers has been well received by many ARM development engineers. The large user base (many of whom have transitioned from the 8-bit machines like the 51 series), along with its simple management window and user-friendly UI, has made it quite popular. After all, it has now become ARM’s ‘favorite child’, and its support for ARM core products is quite good.

GCC, on the other hand, is quite famous. This product, which is still maintained under the GNU project, has been continuously optimized by many experts, and its powerful compilation efficiency and cross-platform capabilities are widely recognized (since Codewarrior 10.x, the compiler for ARM has integrated GCC).

The purpose of this article is aimed at developers who want to migrate from the GCC platform to the Keil MDK platform (this does not imply that ARMCC is better than GCC; we are not comparing the two here). If you are used to GCC, there might be some differences to note when porting to ARMCC. For instance, anonymous unions are not supported in ARMCC, and to use them in ARMCC, you need to add “#pragma anon_unions” in front, while this format is directly supported in GCC.

Simple Use of GCC to Compile C Files in Keil Projects

If developers want to migrate the entire project originally under GCC to Keil MDK, and if there are a large number of such definitions in the project, modifying them one by one would definitely be a headache. So, is there a simple and straightforward method? Well, since I mentioned it, there must be! It’s actually quite simple. We go to Project->Options… and set it as shown in the following image, adding “–gnu” will enable the use of the GNU toolchain GCC to compile C files in the Keil project. Isn’t that a bit too simple?

Simple Use of GCC to Compile C Files in Keil Projects

Finally, I need to mention that this “–gnu” is to be added under the C/C++ tab. If you create a new project in Keil and add the automatically generated startup code (startup_xxx.s), be cautious about adding “–gnu” under the ASM tab, because the assembly format under ARMCC is completely different from GCC, so using GCC to compile assembly generated by Keil is not feasible; this is something to pay attention to.

Correction: Thanks to the blogger below for the correction. “–gnu” is actually to add support for GNU extended format in ARMCC. Of course, Keil can add GCC compilers through the menu “Project > Manage > Components, Environment, Books..” but you need to have the GCC compiler installed in advance.

Simple Use of GCC to Compile C Files in Keil Projects

Leave a Comment