在我的生命中,我无法使用makefile正确编译该文件,而我拥有使用OpenGL的c ++文件。
一些文件依赖于其他文件
我有5个档案
〜依赖〜
在主要CPP
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "Vector.h"
在VECTOR.CPP
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "Vector.h"
#include "Utility.h"
实用工具
#include "Utility.h"
我尝试并整理了各种标志后,这是makefile当前的样子
program1: main.o Vector.o Utility.o
g++ -std=c++11 main.o Vector.o Utility.o -o program1
main.o: main.cpp Vector.h
g++ -std=c++11 main.cpp -lglut -lGL -lGLU -lglut -lm
Vector.o: Vector.cpp Vector.h Utility.h
g++ -std=c++11 Vector.cpp -lglut -lGL -lGLU -lglut -lm
Utility.o: Utility.cpp Utility.h
g++ -std=c++11 Utility.cpp -lglut -lGL -lGLU -lglut -lm
clean:
-rm -f *.o
键入“ make”将输出以下结果:
g++ -std=c++11 main.cpp -lglut -lGL -lGLU -lglut -lm
g++ -std=c++11 Vector.cpp -lglut -lGL -lGLU -lglut -lm
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In (.text+0x20): undefined reference to 'main'
collect2: error: ld returned 1 exit status
makefile:6: recipe for target 'Vector.o' failed
make: ***[Vector.o] Error 1
我该如何修复我的makefile文件?谢谢
-c
objects := main.o Vector.o Utility.o
CXXFLAGS := -std=c++11
program1: CC := $(CXX)
program1: LDLIBS := -lglut -lGL -lGLU -lglut -lm
program1: $(objects)
$(LINK.o) $^ $(LDLIBS) -o $@
main.o: Vector.h
Vector.o: Vector.h Utility.h
Utility.o: Utility.h
.PHONY: clean
clean:
$(RM) $(objects)
如果将main.o
/更改main.cpp
为program1.o
/ program1.cpp
,则可以通过program1
完全摆脱配方来进一步简化事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句