作者: 付汉杰 hankf@xilinx.com hankf@amd.com,文章来源:博客园
测试环境: PetaLinux 2021.2
在Petalinux创建的应用程序模板,只支持编译一个C文件。
使用下面的文件,可以编译目录下的所有C、C++文件。
APP = qdma-ep-rw
#
# CC=$(CROSS_COMPILE)gcc
# CXX=$(CROSS_COMPILE)g++
# Common options
CFLAGS= -g -O3
LIBS =
# Options for extra libraries
#CFLAGS_OPENCV = `pkg-config opencv --cflags`
#LIBS_OPENCV = `pkg-config opencv --libs`
# Find all C files and create object file list
C_SRC = $(wildcard *.c)
C_OBJ = $(patsubst %c, %o, $(C_SRC))
# Find all Cpp files and create object file list
CPP_SRC = $(wildcard *.cpp)
CPP_OBJ = $(patsubst %cpp, %o, $(CPP_SRC))
# Include directory
INC_PATH=-I. -I./include -I../include
all: build
build: $(APP)
# Compile C files
.c.o:
$(CXX) -c $(CFLAGS) $(INC_PATH) -o $@ $< $(LIBS)
# Compile Cpp files
.cpp.o:
$(CXX) -c $(CFLAGS) $(INC_PATH) -o $@ $< $(LIBS)
$(APP): $(C_OBJ) $(CPP_OBJ)
$(CXX) -o $@ $(C_OBJ) $(CPP_OBJ) $(LDFLAGS) $(LDLIBS)
clean:
rm -f $(APP) *.o
当使用$(CC),也就是$(CROSS_COMPILE)gcc,编译C文件时,petalinux报告下列错误。当改为$(CXX)后,petalinux编译正常。
Command '['aarch64-xilinx-linux-objcopy', '--only-keep-debug', '/proj/hankf/vck190/v212/dapd-0211-xsa-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/qdma-ep-rw/1.0-r0/package/usr/bin/qdma-ep-rw', '/proj/hankf/vck190/v212/dapd-0211-xsa-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/qdma-ep-rw/1.0-r0/package/usr/bin/.debug/qdma-ep-rw']' returned non-zero exit status 1.
Subprocess output:aarch64-xilinx-linux-objcopy: Unable to recognise the format of the input file `/proj/hankf/vck190/v212/dapd-0211-xsa-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/qdma-ep-rw/1.0-r0/package/usr/bin/qdma-ep-rw'
DEBUG: Python function split_and_strip_files finished
DEBUG: Python function do_package finished