编译使用动态库, 编译ko makefile

动态库makefile 举例

CURR_DIR := $(shell pwd)

MAKE = make
ASAN_CFLAGS += -fsanitize=address -fsanitize-recover=address 
ASAN_OPTIONS=halt_on_error=0
ASAN_LDFLAGS += -fsanitize=address -g1
CLEAN = make clean
CC = /opt/toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
LDFLAGS += -I./
export CC
RM = rm -rf
TARGET_NAME = nca9555.so

$(TARGET_NAME): nca9555.c
	$(CC) -shared -fPIC nca9555.c -o $(TARGET_NAME) $(LDFLAGS) 
	cp nca9555.so ../
	@echo $(shell pwd)
	
clean:
	rm nca9555.so
.PHONY:clean

使用动态库举例

CURR_DIR := $(shell pwd)

MAKE = make
ASAN_CFLAGS += -fsanitize=address -fsanitize-recover=address 
ASAN_OPTIONS=halt_on_error=0
ASAN_LDFLAGS += -fsanitize=address -g1
CLEAN = make clean
CC = /opt/toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
LDFLAGS += -I./
export CC
RM = rm -rf
TARGET_NAME = io_test

$(TARGET_NAME):main.c 
	$(CC) main.c -o $(TARGET_NAME) nca9555.so
	@echo $(shell pwd)
	
clean:
	rm io_test
.PHONY:clean

编译ko

COMPILE=/media/xyding_60035/quanzhi/new_T3/lichee/out/sun8iw11p1/linux/common/buildroot/host/usr/bin/arm-linux-gnueabihf-
CC:=$(CROSS_COMPILE)gcc
LD:=$(CROSS_COMPILE)ld

obj-m:=gnss.o  

KERNEL_PATH := /media/xyding_60035/quanzhi/new_T3/lichee/linux-3.10

PWD:=$(shell pwd)

all:
	make ARCH=arm CROSS_COMPILE=$(COMPILE) -C $(KERNEL_PATH) M=$(PWD) modules

clean:
	make -C $(KERNEL_PATH) SUBDIRS=$(PWD) clean

你可能感兴趣的:(linux,运维,服务器)