mainajaved
mainajaved

Reputation: 8173

How to cross compile in linux

I have a makefile and if I want to compile it for different compilers what changes do I need in my makefile? One I know is to change CC value that is my compiler. What other changes do I need? For example my here is my make file:

CC=gcc
CFLAGS=-c -Wall

all: hello

hello: main.o factorial.o hello.o
    $(CC) main.o factorial.o hello.o -o hello

main.o: main.cpp
    $(CC) $(CFLAGS) main.cpp

factorial.o: factorial.cpp
    $(CC) $(CFLAGS) factorial.cpp

hello.o: hello.cpp
    $(CC) $(CFLAGS) hello.cpp

clean:
    rm -rf *o hello

What changes do I need it to compile it for an other processor? And how to know the name of compiler linker arch etc. of the processor?

Upvotes: 1

Views: 875

Answers (2)

Sergei Nikulov
Sergei Nikulov

Reputation: 5110

In make define CC as

CC=$(CROSS)gcc

Invoke make like

CROSS=ppc_8xx- make 

CROSS can be arm-linux-gnu- or whatever.

Upvotes: 0

Sebastian Mach
Sebastian Mach

Reputation: 39089

It depends.

If you are already using a compiler that can emit code for different targets, it is a question of setting the proper flags, e.g. imagine CC=süper-cross-compiler and CFLAGS=eye-phone.

If you must switch to another compiler which has compatible flags, you would have to to change your $(CC) variable and probably others, or possibly you set another alias in your shell environment.

There's a Linux port of the GCC windows port MinGW. Some distributions ship it as mingw-gcc; on them, you would CC=mingw-gcc.

In any case and in general, you have to tweak multiple stuffs. It all depends on the exact circumstances.

Upvotes: 1

Related Questions