最近刚好需要做C和C++混合编译,搞一个Makefile
CC = arm-poky-linux-gnueabi-gcc
C++ = arm-poky-linux-gnueabi-g++
LINK = arm-poky-linux-gnueabi-g++
LIBS = -lz -lm -lpcre -lpthread
#编译.so must add -fPIC option https://www.cnblogs.com/cswuyg/p/3830703.html
CCFLAGS = -c -g -fPIC
C++FLAGS = -c -g -fPIC
#期望得到的执行文件或动态库.so
TARGET=libxx.so
INCLUDES = -I. -I../../
C++FILES = $(wildcard *.cpp ./../common/*.cpp)
CFILES = $(wildcard *.c ./../common/*.c)
OBJFILE = $(CFILES:.c=.o) $(C++FILES:.cpp=.o)
all:$(TARGET)
$(TARGET): $(OBJFILE)
$(LINK) $^ $(LIBS) -Wall -fPIC -shared -o $@
%.o:%.c
$(CC) -o $@ $(CCFLAGS) $< $(INCLUDES)
%.o:%.cpp
$(C++) -o $@ $(C++FLAGS) $< $(INCLUDES)
install:
tsxs -i -o $(TARGET)
clean:
rm -rf $(TARGET)
rm -rf $(OBJFILE)