A simple make file for C / C ++ targets used with arm-linux-gcc

I would like to cross-compile a simple program for the ARM architecture using the arm-linux-gcc compiler suite [arm-linux-gcc (Buildroot 2011.08) 4.3.6]. I tried using a simple make file to compile C code and another simple make file to compile C ++ code. For example, my makefile for C code is reproduced below, but it does not create an ELF binary to work on my embedded system. The host system is x64 GNU Linux.

Here is a list of my very simple makefile for the C program:

CC=arm-linux-gcc CFLAGS=-Wall main: test.o clean: rm -f test test.o 

The make file created above only creates an object file with the extension .o and does not create the binary ELF file.

I have Googled for a good solution, but I can’t find a single web page showing an example of cross-compiling ARM files for C and C ++ programs. Perhaps the answer to this post may show such examples.

+4
source share
2 answers

I tried your Makefile and changed the following:

 test: test.o 

It worked after that and created a binary called test . There seems to be some kind of implicit rule that knows how to bind whatever if one of its dependencies whatever.o .

Another way is to explicitly specify the rule:

 main: test.o $(CC) -o $@ $$ 

It uses special macros $@ (which means the target) and $$ (which means the dependencies).

+3
source

See the GNU manual ( info make ), section 10.2 . It has a directory of implicit rules, i.e. Rules in which you do not need to explicitly specify commands. Like @GregHewgill, the "implicit assembly rule" Single Object Linking "builds N from No , but the name must match. Thus, you can name your executable file as your object file, in which case

 test: 

or (more standard as it defines the purpose of all )

 all : test 

quite enough. You can also write a rule explicitly, as described in Greg Hewgill. In this case, the standard rule:

  $(CC) $(LDFLAGS) No $(LOADLIBES) $(LDLIBS) 

Include LDFLAGS and LDLIBS in your Makefile, this will make life easier for users.

(sic: I think LOADLIBES is really LOADLIBS, and the author skipped -o ).

In general, I would recommend autoconf and automake instead of manual files. Provides you with a set of Makefile functions for very little work.

+5
source

Source: https://habr.com/ru/post/1389338/


All Articles