makefile内容如下:
BIN_NAME=./mainTest.so ## dst file name
DEPEND_SO_PATH=-L./ ## depend on so file path --> -L../bin
##DEPEND_LIB_NAME=-l ## depend on lib file name, libaa.lib --> -laa
PATH_DYN='-Wl,-rpath,$$ORIGIN/' -Wl,-rpath=../bin ## so file load path
HEADER_FILE= -I../ ## header file path
CPP_FILE=./main.cpp ## cpp file name
CC=g++ -shared -fno-rtti -Werror -pipe -Wall -Wno-unused -w -O2 -fPIC ## g++/gcc command, if so need "-shared", if run executable program delete "-share"
OBJS= $(CPP_FILE:%.cpp=%.o)
%.o:%.cpp
$(CC) -c $(DEPEND_SO_PATH) $(HEADER_FILE) $< -o $@ ## create .o file
$(BIN_NAME): $(OBJS)
$(CC) -o $(BIN_NAME) $(OBJS) $(DEPEND_SO_PATH) $(DEPEND_LIB_NAME) $(PATH_DYN) ## create so file or executable program
@echo "build success!" $(BIN_NAME)
clean:
rm -f $(OBJS)
rm -f $(BIN_NAME)
执行方式: