Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to cross compile for ARM on Ubuntu conditionally?

I have written the following make file

all: writer.o

writer.o:
    gcc -Wall writer.c -o writer

clean:
    rm *.o

How do I add a functionality to this make file such that I am able to generate an application for the native build platform when GNU make variable CROSS_COMPILE is not specified on the make command line.However, when CROSS_COMPILe is set, I should generate a cross compiled output file using the compiler, aarch64-none-linux-gnu-gcc.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Set the CROSS_COMPILE variable itself to the compiler prefix. So for native builds:

CROSS_COMPILE = 

(i.e. there’s nothing, the variable is "empty").

And for cross-compilation:

CROSS_COMPILE = aarch64-none-linux-gnu-

Then set:

CC = $(CROSS_COMPILE)gcc

To complement the above, use implicit rules to build the program:

all: writer

writer: writer.o

That’s all that you need.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading