MakeFile目标目录

时间:2014-04-10 19:52:40

标签: c++ makefile

我的代码在src文件夹中。 src / Client包含用于创建客户端应用程序的makefile。 src / Server包含用于创建客户端应用程序的makefile。 我在与src相同的文件夹中有一个bin文件。 名为ad的文件夹包含src和bin。 在bin我有一个makefile

all: 
    cd ../src/Server; make
    cd ../src/Client; make

clean: 
    cd ../src/Server; make clean
    cd ../src/Client; make clean

我的问题是我想要bin中的所有可执行文件,但现在它们是在Server and Client文件夹中创建的。

我在客户端文件夹中的makefile:

# Define the compiler and the linker. The linker must be defined since
# the implicit rule for linking uses CC as the linker. g++ can be
# changed to clang++.
CXX = g++
CC  = g++

# Define preprocessor, compiler, and linker flags. Uncomment the # lines
# if you use clang++ and wish to use libc++ instead of libstd++.
CPPFLAGS  =-I.. -I ../database

CXXFLAGS =  -g -O2 -Wall -W -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast 
CXXFLAGS += -std=c++11 
LDFLAGS =   -g -L.. -L../database
#CPPFLAGS += -stdlib=libc++
#CXXFLAGS += -stdlib=libc++
#LDFLAGS +=  -stdlib=libc++

# Libraries
LDLIBS = -lclientserver -ldatabase

# Targets
PROGS = interface


all: $(PROGS)

# Targets rely on implicit rules for compiling and linking
# The dependency on libclientserver.a is not defined.
interface: interface.o com.o ans.o

# Phony targets
.PHONY: all clean

# Standard clean
clean:
    rm -f *.o $(PROGS)

# Generate dependencies in *.d files
%.d: %.cc
    @set -e; rm -f $@; \
         $(CPP) -MM $(CPPFLAGS) $< > $@.$$$$; \
         sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
         rm -f $@.$$$$

# Include the *.d files
SRC = $(wildcard *.cc)
include $(SRC:.cc=.d)

我应该在此档案中更改什么?

2 个答案:

答案 0 :(得分:0)

通常,您的主makefile是构建可执行文件的内容。辅助的应该是制作目标文件。在这种情况下,将可执行文件移动到根文件夹是可行的:

mv src/Client/$(EXECUTABLE) src/bin
mv src/Server/$(EXECUTABLE) src/bin

如果您确实想要做到正确,请链接主要生成

中的目标文件
all:
      $(CC) $(LDFLAGS) $(CLIENT_FOLDER)/*.o $(SERVER_FOLDER)/*.o $(BIN_FOLDER)/$(EXECUTABLE)

使aux文件只需编译

答案 1 :(得分:0)

# Define the compiler and the linker. The linker must be defined since
# the implicit rule for linking uses CC as the linker. g++ can be
# changed to clang++.
CXX = g++
CC  = g++

# Define preprocessor, compiler, and linker flags. Uncomment the # lines
# if you use clang++ and wish to use libc++ instead of libstd++.
CPPFLAGS  =-I.. -I ../database

CXXFLAGS =  -g -O2 -Wall -W -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast 
CXXFLAGS += -std=c++11 
LDFLAGS =   -g -L.. -L../database
#CPPFLAGS += -stdlib=libc++
#CXXFLAGS += -stdlib=libc++
#LDFLAGS +=  -stdlib=libc++

# Libraries
LDLIBS = -lclientserver -ldatabase

# Targets
PROGS = interface


all: $(PROGS)

# Targets rely on implicit rules for compiling and linking
# The dependency on libclientserver.a is not defined.
interface: interface.o com.o ans.o
     $(CXX) -o ../../bin/$@ $^ $(LDLIBS) $(LDFLAGS)
# Phony targets
.PHONY: all clean

# Standard clean
clean:
    rm -f *.o $(PROGS)

# Generate dependencies in *.d files
%.d: %.cc
    @set -e; rm -f $@; \
         $(CPP) -MM $(CPPFLAGS) $< > $@.$$$$; \
         sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
         rm -f $@.$$$$

# Include the *.d files
SRC = $(wildcard *.cc)
include $(SRC:.cc=.d)

这有效