Question

I cannot find an option for the ARM GNU toolchain to compile multiple c files at the same time. I use make -j5 all the time when compiling using gcc. Helps speed up compile time dramatically. Be nice if ARM GNU had a similar option.

Here is my setup: --Fedora 20 --Core i5 --Eclipse with ARM GNU plugin --ARM GNU 4.8-2014-q1-update (from here: https://launchpad.net/gcc-arm-embedded) --Target uP: STM32F205RB

I've tried to get CodeSourcery GCC working, unsuccessfully. ARM GNU seemed to work well after little setup. CodeSourcery GCC should have a -j option, as we cross compile all the time for embedded linux.

Était-ce utile?

La solution

GCC is not multi-threaded. The -j<n> switch is specific to make build system, not the compiler. It tells make how many tasks it can run in parallel.

If you run make -j4 you can observe in your task manager/top/process list that it tries to run 4 instances of GCC compiling 4 independent *.c files at the same time.

To make use of -j command you must have a Makefile in your project that can benefit from it. It should have multiple independent targets, so that they can be launched in parallel.

If you are lost in the terminology, I advice you to look at make tutorial, such as this one: http://mrbook.org/tutorials/make/

The usual strategy here is to have a separate target for every c or cpp file in our project. That way make can easily spawn multiple compiler processes for each compilation unit. Once all *.o files are generated, they are linked.

Let's see at this example snippet:

SRCS  := main.c func.c other.c another_file.c ...
OBJS  := $(SRCS:.c=.o)

objects: $(OBJS)

%.o: %.c
  gcc -o $(@) -c $(<)

We pass a list of c files, change them to corresponding o file using suffix substitution and treat the list of *.o files as targets. Now the make can compile each c file in parallel.

In contrast, if we do something like this:

SRCS  := main.c func.c other.c another_file.c ...

all:
  gcc $(SRCS) -o a.out

...we won't benefit from -j switch at all, because there is only one target.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top