Makefile sample

Makefile sample

DIR

bin

include

lib

src

main.cpp

Makefile

 

 


CROSS_COMPILE	  =arm-linux-gnueabihf-
CC				  =$(CROSS_COMPILE)gcc
CXX				  =$(CROSS_COMPILE)g++
AR                =$(CROSS_COMPILE)ar cqs
OBJCOPY           =$(CROSS_COMPILE)objcopy
NM                =$(CROSS_COMPILE)nm -P
STRIP             =$(CROSS_COMPILE)strip
LD				  =$(CROSS_COMPILE)ld
 
VPATH := ./src:./include
CFLAGS=-I . -I ./include
LIBS +=-L . -L ./lib
 
vpath *.cpp .
vpath *.cpp ./src
vpath *.h .
vpath *.h ./include
 
SRC+=$(shell ls *.cpp)
SRC+=$(shell ls ./src/*.cpp)
 
 
OBJS=$(patsubst %.cpp,%.o, $(SRC))
 
 
 
.PHONY: all clean 

all: $(OBJS)
	$(CXX) -o $@  $^ 
	echo $(OBJS)

clean:
	$(RM) -rf *.o
 

 
 
 
%.o: %.cpp
	$(CXX) -o $@ -c $<  $(CFLAGS)

FLTK:

交叉编译:

1) Download Raspberry cross toolchain on Ubuntu ;

2) Sync rootfs of Raspberry SD card;

3) Download FLTK

4) 交叉编译

export PATH=/opt/workspace/Raspberry/raspberry_chaintool/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/bin:$PATH

在Makefile中把fluid 和test删掉。

CC=arm-linux-gnueabihf-gcc ./configure --host=arm-linux --x-includes=/opt/workspace/Raspberry/respberry_FS/usr/include --x-libraries=/opt/workspace/Raspberry/respberry_FS/usr/lib  --enable-gl --includedir=/opt/workspace/Raspberry/respberry_FS/usr/include/arm-linux-gnueabihf --libdir=/opt/workspace/Raspberry/respberry_FS/usr/lib/arm-linux-gnueabihf

 

make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm-linx --trace

Cross compile raspberry FLTK example on Ubuntu.

Makefile:

ROOTFS=/opt/Rasp/rootfs
CROSS_COMPILE=arm-linux-gnueabihf-
CC=$(CROSS_COMPILE)gcc
CXXFLAGS =  -I$(ROOTFS)/usr/include/arm-linux-gnueabihf\
			-I$(ROOTFS)/usr/include \
			-I$(ROOTFS)/usr/include/libpng16 \
			-I$(ROOTFS)/usr/include/freetype2 \
			-D_LARGEFILE_SOURCE \
			-D_LARGEFILE64_SOURCE \
			-D_FILE_OFFSET_BITS=64 \
			-D_THREAD_SAFE -D_REENTRANT\
			-I/opt/Rasp/cross_FLTK/include
CXXLIBS = -L$(ROOTFS)/lib/arm-linux-gnueabihf -L$(ROOTFS)/usr/lib/arm-linux-gnueabihf -L/opt/Rasp/cross_FLTK/lib  -lfltk  -lX11 -lxcb -lXext -lXdmcp -ldl -lXau -lbsd -lstdc++ -lm

main:main.o
	${CC} -o $@ $^ ${CXXFLAGS}  ${CXXLIBS}
	
main.o:main.cpp
	${CC} -o $@ -c $^ ${CXXFLAGS} ${CXXLIBS}

 

你可能感兴趣的:(UBUNTU)