1. Makefile编写
makefile如下所示,编译生成静态库;
$^: 表示所有的.o文件
$@: 表示目标文件
CROSS = CC = $(CROSS)arm-linux-gnueabi-gcc CXX = $(CROSS)arm-linux-gnueabi-g++ DEBUG = -g CFLAGS = $(DEBUG) -Wall -c -fPIC -pthread -mfloat-abi=hard MV = mv -f RM = rm -rf LN = ln -sf TARGET = RTK TOP_PATH = $(shell pwd) INC_PATH = $(TOP_PATH) SRC_PATH += $(TOP_PATH) SRC_PATH += $(TOP_PATH)/gsl SRC_PATH += $(TOP_PATH)/BASEDLL SRC_PATH += $(TOP_PATH)/GNSSDLL SRC_PATH += $(TOP_PATH)/RTIEDLL DIRS = $(shell find $(SRC_PATH)) FILES = $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cpp)) BUILD_DIR = $(TOP_PATH)/build ########################################################## # modules ########################################################## ########################################################## # srcs ########################################################## SRCS_CPP += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cpp)) SRCS_CC += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc)) SRCS_C += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.c)) ########################################################## # objs ########################################################## OBJS_CPP = $(patsubst %.cpp, %.o, $(SRCS_CPP)) OBJS_CC = $(patsubst %.cc, %.o, $(SRCS_CC)) OBJS_C = $(patsubst %.c, %.o, $(SRCS_C)) ########################################################## # paths ########################################################## ########################################################## # libs ########################################################## ########################################################## # building ########################################################## all:$(TARGET) $(TARGET) : $(OBJS_CPP) $(OBJS_CC) $(OBJS_C) #$(CXX) -shared -fpic $^ -o lib.so ar -crv libRTK.a $^ $(OBJS_CPP):%.o : %.cpp $(CXX) $(CFLAGS) $< -o $@ -I$(INC_PATH) $(OBJS_CC):%.o : %.cc $(CXX) $(CFLAGS) $< -o $@ -I$(INC_PATH) $(OBJS_C):%.o : %.c $(CXX) $(CFLAGS) $< -o $@ -I$(INC_PATH) $(OBJS_C):%.o : %.c $(CC) $(CFLAGS) $< -o $@ -I$(INC_PATH) .PHONY : clean clean: @ $(RM) $(TARGET) $(OBJS_CPP) $(OBJS_CC) $(OBJS_C)
2. yocto的.bb文件包含静态库
DESCRIPTION = "A simple UART test application" SECTION = "extras" LICENSE = "GPLv2+ & LGPLv2.1+" PR = "r0" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" inherit externalsrc EXTERNALSRC_pn-uart-test ?= "${ST_LOCAL_SRC}carproc-app/uart-test" FILES_${PN} = "${bindir}/uart-test" do_compile() { ${CXX} ${CXXFLAGS} ${LDFLAGS} -pthread ${S}/uart_test.cpp ${ST_LOCAL_SRC}carproc-app/uart-test/lib/libRTK.a -o uart-test -I ${ST_LOCAL_SRC}carproc-app/uart-test } do_install_append() { install -d ${D}${bindir} install -m 0755 ${B}/uart-test ${D}${bindir} }
Makefile编译要跟yocto一致使用交叉编译,编译选项尽可能一致
标签:yocto,OBJS,%.,SRC,编译,test,Linux,################################################ From: https://www.cnblogs.com/boring-luobo/p/16960223.html