2015-07-11 54 views
1

我试图寻找答案,但无济于事,所以给我的项目已得到了下面的结构C++的makefile构建多个DLL和项目结构

makefile 
./src 
    strings.cpp 
    networking.cpp 
./bin 
    strings.dll 
    networking.dll 
./build 
    strings.o 
    networking.o 
./include 
    strings.h 
    networking.h 
./lib 
    boost 

我很新的Makefile文件,并从研究我曾经做过到目前为止,我还设法让这一起(不是很复杂,我知道)

CC = g++ 
SRC = src/strings.cpp 
OUT = bin/strings.dll 
OBJ = build/strings.o 
INC= -I include 

all: strings.dll 

strings.dll: strings.o 
    $(CC) -shared -o $(OUT) $(OBJ) 

strings.o: $(SRC) 
    $(CC) $(INC) -DBDLL -c $(SRC) -o $(OBJ) 

的问题/疑问我已经是

1之后,一直都会通过量整个编译过程,即使我没有改变源代码?

2-我怎样才能让事情更有效?我看到了使用通配符等的人的例子,但我很难跟随。我是否可以使用通配符开始,因为我需要为每个目标单独使用dll?

3 - 比方说,我介绍algorithms.h and algorithms.cpp什么是建议包括在构建?

感谢您的任何帮助,真的很感激它

回答

1

首先。整个编译过程是因为搜索目标“strings.dll”,但建立bin/strings.dll。所以,如果你如果前提改变它替换到

bin/strings.dll: strings.o 
    $(CC) -shared -o $(OUT) $(OBJ) 

bin/strings.o: $(SRC) 
    $(CC) $(INC) -DBDLL -c $(SRC) -o $(OBJ) 

构建将只执行目标(BIN/strings.o和斌/ strings.dll)。

其次 - 基本上通配符用于搜索目录内的所有文件,如下所示:$(whildcard *.cpp)求值为当前目录内的所有cpp文件。所以,你可以写这样的事情:

all_sources = $(wildcard *.cpp) 
all_objects = $(addprefix bin/,$(all_sources:.cpp=.o)) 

all: bin/strings.dll 

bin/strings.dll: $(all_objects) 
    <how to build strings.dll from objects> 

bin/%.o: %.cpp 
    <how to build objects inside bin dir from cpp of current dir>  

三 - 生成文件没有建立系统本身来说它只是具有领域特定语言的工具。你可以使用make编写自己的构建系统。如果你想做好准备,你最好学习automake/cmake/......其中很多。

此外,开始使用制作工具是一个很好的开始。不要停下来,你会惊讶它内部的力量。

+0

感谢您的详细解答...真正帮助超过了我的要求 –