提问人:Vincent Han 提问时间:3/4/2023 最后编辑:genpfaultVincent Han 更新时间:3/4/2023 访问量:71
使用 OpenGL 函数时,make 文件出现链接器错误
Linker error with make file when using OpenGL functions
问:
我在程序中使用 openGL 库时遇到了一些问题。首先,我确实正确地实现了所有相关的东西:
#define GL_SILENCE_DEPRECATION
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
而且,在我的这个程序中,我的任务是绘制一堆矩形,我在编译时遇到了一些问题。这是我使用make文件进行编译时的错误消息:
Undefined symbols for architecture arm64:
"_glBegin", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
"_glClear", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
display() in mondrian-a92186.o
"_glClearColor", referenced from:
_main in mondrian-a92186.o
"_glColor3f", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
"_glEnd", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
"_glFlush", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
display() in mondrian-a92186.o
"_glLineWidth", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
"_glLoadIdentity", referenced from:
display() in mondrian-a92186.o
"_glMatrixMode", referenced from:
display() in mondrian-a92186.o
"_glScalef", referenced from:
display() in mondrian-a92186.o
"_glTranslatef", referenced from:
display() in mondrian-a92186.o
"_glVertex2i", referenced from:
drawRegionsRec(treeNode*) in mondrian-a92186.o
"_glutCreateWindow", referenced from:
_main in mondrian-a92186.o
"_glutDisplayFunc", referenced from:
_main in mondrian-a92186.o
"_glutInit", referenced from:
_main in mondrian-a92186.o
"_glutInitDisplayMode", referenced from:
_main in mondrian-a92186.o
"_glutInitWindowPosition", referenced from:
_main in mondrian-a92186.o
"_glutInitWindowSize", referenced from:
_main in mondrian-a92186.o
"_glutMainLoop", referenced from:
_main in mondrian-a92186.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mondrian] Error 1
从本质上讲,我调用的每个 OpenGL 函数都是无法识别的,然后我得到一个链接器错误。
我确保我的 makefile 也是正确的。
PLATFORM = $(shell uname)
## Compilation flags
##comment out one or the other
##debugging
CFLAGS = -g
##release
#CFLAGS = -O3 -DNDEBUG
LDFLAGS=
CFLAGS+= -Wall
ifeq ($(PLATFORM),Darwin)
## Mac OS X
CFLAGS += -m64 -Wno-deprecated
INCLUDEPATH=-I/system/usr/local/include
LDFLAGS+= -m64 -lc -framework AGL -framework OpenGL -framework GLUT -framework Foundation
else
## Linux
CFLAGS += -m64
INCLUDEPATH = -I/usr/include/GL/
LIBPATH = -L/usr/lib64 -L/usr/X11R6/lib
LDFLAGS+= -lGL -lglut -lrt -lGLU -lX11 -lm -lXmu -lXext -lXi
endif
CC = g++ -O3 -Wall $(INCLUDEPATH)
PROGS = mondrian
default: $(PROGS)
mondrian: mondrian.o geom.o rtimer.o
$(CC) -o $@ mondrian.o geom.o rtimer.o $(LDFLAGS)
mondrian.o: mondrian.cpp geom.h rtimer.h
$(CC) -c $(CFLAGS) mondrian.cpp -o $@
如何解决这个问题?
答: 暂无答案
评论
... in mondrian-a92186.o ...
mondrian-a92186