一个简单的makefile文件尝试
SHARED_CFLAGS=-fPIC -shared SHARED_SRC=calac_level.cpp calac_level.h BIN_SRC=main.cpp SHARED_PATH=-L ./ -lcalac_level BIN_CFLAGS= -Wl,-rpath,./ -g CC_VERSION=-std=c++11 ECHO_RED_COLOR=\033[31m ECHO_END=\033[0m LIB_TARGET=libcalac_level.so BIN_TARGET=main all: clean $(LIB_TARGET) $(BIN_TARGET) $(LIB_TARGET):$(SHARED_SRC) @echo -e "$(ECHO_RED_COLOR)/$/^ $^ /$/< $< \$\@ $@$(ECHO_END)" g++ $^ $(SHARED_CFLAGS) -o $@ $(CC_VERSION) $(BIN_TARGET):$(BIN_SRC) g++ $^ -o $@ $(SHARED_PATH) $(BIN_CFLAGS) $(CC_VERSION) .PHONY: clean all clean: rm -rf $(BIN_TARGET) $(LIB_TARGET)