开发环境 :
ubuntu : 16.04
IDE : vscode
Lau : C++
工程结构如下 :
Dependencies : 依赖库生成工程.
StartUpProject : 启动工程.
StartUpProject -> makefile
CC = g++
SUB_DIR := ./Dependencies/
all : $(SUB_DIR)
@echo Success
$(SUB_DIR) : ECHO
cd ../$(SUB_DIR) && make && cd ../StartUpProject
ECHO :
@echo $(SUB_DIR)
@echo begin compile
@echo
Dependencies -> makefile
cc = g++
src_path = ./src
src = $(wildcard $(src_path)/*.cpp)#指定路径下的所有cpp
obj_path = ./objs
objs =$(patsubst %.cpp, %.o, $(addprefix ./objs/, $(notdir $(src))))
#ndobjs = $(notdir $(src))
include_path = ./include
includes = $(wildcard $(include_path)/*.h)
libs_path = ./libs
target = $(libs_path)/libfun.a
all : $(target) build
$(target) : $(objs)
ar cr $@ $(objs)
build:
@echo $(includes)
@echo $(src)
@echo $(objs)
$(objs) : $(src)
$(cc) -c $< -o $@
运行StartUpProject makefile结果:
./Dependencies/
begin compile
cd .././Dependencies/ && make && cd ../StartUpProject
make[1]: Entering directory '/home/erric/Codes/Linux/Cmake/cmake_tutorial/m4step/Dependencies'
g++ -c src/fun.cpp -o objs/fun.o
g++ -c src/fun.cpp -o objs/test.o
ar cr libs/libfun.a ./objs/fun.o ./objs/test.o
./include/test.h ./include/fun.h
./src/fun.cpp ./src/test.cpp
./objs/fun.o ./objs/test.o
make[1]: Leaving directory '/home/erric/Codes/Linux/Cmake/cmake_tutorial/m4step/Dependencies'
Success
码云下载地址 :https://gitee.com/DomTech/Cmake
欢迎各位大大指教。