将静态库与gnu g ++链接:没有这样的文件或目录,Makefile

时间:2016-06-18 10:38:39

标签: c++ makefile static-linking

我使用makefile编译我的简单应用程序。这是:

project = "MyProject" AND updated > -1d AND sprint IS EMPTY

然而,似乎我在链接静态库时遇到问题。执行CURRDIR = `basename $(PWD)` MAINAPP = main SECTION = section POINT = point FIGURE = figure CIRCLE = circle TRIANGLE = triangle RECTANGLE = rectangle MAINSRC = $(MAINAPP).cpp SECTIONSRC = $(SECTION).cpp CIRCLESRC = $(CIRCLE).cpp TRIANGLESRC = $(TRIANGLE).cpp RECTANGLESRC = $(RECTANGLE).cpp MAINKOM = $(MAINAPP).o SECTIONKOM = $(SECTION).o CIRCLEKOM = $(CIRCLE).o TRIANGLEKOM = $(TRIANGLE).o RECTANGLEKOM = $(RECTANGLE).o SECTIONHEADER = $(SECTION).h POINTHEADER = $(POINT).h CIRCLEHEADER = $(CIRCLE).h TRIANGLEHEADER = $(TRIANGLE).h RECTANGLEHEADER = $(RECTANGLE).h FIGUREHEADER = $(FIGURE).h MAINEXE = $(MAINAPP).x COMPILER = g++ COMPILERCOPTIONS = -Wall -c LINKER = $(COMPILER) LINOP = -Wall BIBSTAT = libfigures.a BIBKOM = section.o triangle.o rectangle.o circle.o AR = ar AROP = rv $(BIBSTAT): $(BIBKOM) $(AR) $(AROP) $@ $? all: $(MAINEXE) $(SECTIONKOM): $(SECTIONSRC) $(COMPILER) $(COMPILERCOPTIONS) $(SECTIONSRC) $(CIRCLEKOM): $(CIRCLESRC) $(COMPILER) $(COMPILERCOPTIONS) $(CIRCLESRC) $(TRIANGLEKOM): $(TRIANGLESRC) $(COMPILER) $(COMPILERCOPTIONS) $(TRIANGLESRC) $(RECTANGLEKOM): $(RECTANGLESRC) $(COMPILER) $(COMPILERCOPTIONS) $(RECTANGLESRC) $(MAINKOM): $(MAINSRC) $(SECTIONHEADER) $(POINTHEADER) $(CIRCLEHEADER) $(TRIANGLEHEADER) $(RECTANGLEHEADER) $(FIGUREHEADER) $(COMPILER) $(COMPILERCOPTIONS) $(MAINSRC) $(MAINEXE): $(MAINKOM) $(SECTIONKOM) $(CIRCLEKOM) $(TRIANGLEKOM) $(RECTANGLEKOM) $(BIBSTAT) $(LINKER) -o $@ $(LINOP) $^ $(MAINEXE) $(MAINKOM) $(SECTIONKOM) $(CIRCLEKOM) $(TRIANGLEKOM) $(RECTANGLEKOM) run: $(MAINEXE) ./$(MAINEXE) clean: rm -f a.out *~ *.o *.x tar: clean (cd ..; tar cvzf $(CURRDIR).tar.gz $(CURRDIR); ls -altr) 后,这是我的输出:

make all

任何想法我对这个makefile做错了什么?

1 个答案:

答案 0 :(得分:1)

你的最后一个命令是

g++ -o main.x -Wall main.o section.o circle.o triangle.o rectangle.o \
       libfigures.a main.x main.o section.o circle.o triangle.o \
       rectangle.o 

这里有太多的事情:你(1)重复每个对象两次(2)使用两个对象和从它们构建的库(3)使用输入文件列表中的输出文件。

应该是

g++ -o main.x main.o libfigures.a

您可能需要像这样修改makefile规则:

$(MAINEXE): $(MAINKOM) $(BIBSTAT)
    $(LINKER) -o $@ $^