# Makefile for user-space program export PATH=/opt/toolchain/aarch64/bin/:$PATH CC := aarch64-none-linux-gnu-gcc DIR_PATH := /home/user/sdk-v22.04/test_makefile OTHER_DUND_DIR := $(DIR_PATH)/test_file_c OTHER_DUND_H := $(DIR_PATH)/test_file_h CFLAGS := -I$(OTHER_DUND_H) LDFLAGS := #-L/opt/test/lib LDLIBS := #-ltest_library SRC := main.c $(OTHER_DUND_DIR)/test.c #$(wildcard /all_build/*.c) OBJ := $(SRC:.c=.o) TARGET := my_program all: $(TARGET) $(TARGET): $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) %.o: %.c $(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@ $(LDLIBS) clean: # $(warning $(OBJ) $(TARGET)) /bin/rm -f $(OBJ) $(TARGET)
说明:/all_build/*.c 的全部c 文件需要编译,则去掉注释/all_build/*.c的 #,即
SRC := main.c $(OTHER_DUND_DIR)/test.c $(wildcard /all_build/*.c)
若存在链接的文件在其他非标准路径下,则需要手动指定,去掉-L/opt/test/lib的注释 #,即修改为
LDFLAGS := -L/opt/test/lib
指定库名字,去掉#,即为LDLIBS := -ltest_library
LDLIBS := #-ltest_library
标签:示例,app,Makefile,DUND,OTHER,test,PATH,LDLIBS,DIR From: https://www.cnblogs.com/tzj-kernel/p/17763705.html