体系结构 x86_64 的未定义符号:“_glutInit”,引用自:Mac 上 main.o / Netbeans 中的 _main
我的程序是这个谢尔宾斯基垫片。我在 MacBook Pro 上使用 Netbeans,我相信我已经安装了这些库,但它们可能没有正确链接。
#include <iostream>
#include <stdio.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
void myinit(){
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,50.0,0.0,50.0);
glMatrixMode(GL_MODELVIEW);
}
void display(){
GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}};
int i, j, k;
int rand();
GLfloat p[2]={7.5,5.0};
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(k=0; k<5000; k++){
j=rand()*3;
p[0]=(p[0]+vertices[j][0])/2.0;
p[1]=(p[1]+vertices[j][1])/2.0;
glVertex2fv(p);
}
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Sierpinski Gasket");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
以下是编译错误:
Undefined symbols for architecture x86_64:
"_glutInit", referenced from:
_main in main.o
"_glutInitDisplayMode", referenced from:
_main in main.o
"_glutInitWindowSize", referenced from:
_main in main.o
"_glutInitWindowPosition", referenced from:
_main in main.o
"_glutCreateWindow", referenced from:
_main in main.o
"_glutDisplayFunc", referenced from:
_main in main.o
"_glutMainLoop", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/sierpinski] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
My program is this Sierpinski Gasket. I'm using Netbeans on my MacBook Pro and I believe I have the libraries installed but maybe they are not linked correctly.
#include <iostream>
#include <stdio.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
void myinit(){
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,50.0,0.0,50.0);
glMatrixMode(GL_MODELVIEW);
}
void display(){
GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}};
int i, j, k;
int rand();
GLfloat p[2]={7.5,5.0};
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(k=0; k<5000; k++){
j=rand()*3;
p[0]=(p[0]+vertices[j][0])/2.0;
p[1]=(p[1]+vertices[j][1])/2.0;
glVertex2fv(p);
}
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Sierpinski Gasket");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
Here are the compilation errors:
Undefined symbols for architecture x86_64:
"_glutInit", referenced from:
_main in main.o
"_glutInitDisplayMode", referenced from:
_main in main.o
"_glutInitWindowSize", referenced from:
_main in main.o
"_glutInitWindowPosition", referenced from:
_main in main.o
"_glutCreateWindow", referenced from:
_main in main.o
"_glutDisplayFunc", referenced from:
_main in main.o
"_glutMainLoop", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/sierpinski] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要链接 GLUT 框架。在项目属性>链接器>命令行>附加选项,请指定
You need to link the GLUT framework. In Project Properties > Linker > Command Line > Aditional Options, specify
对代码进行轻微修正:
而不是
rand() * 3;
。由于显而易见的原因,这会导致段错误。Slight correction in your code:
and not
rand() * 3;
. That gives seg fault for obvious reasons.在安装 JasPer 的上下文中补充 @user55721 的 GLUT 框架答案。
INSTALL 文档提到了一个特定于架构的
cmake
选项,用于在 Mac OS 上使用 native GLUT:To complement @user55721's GLUT framework answer, in the context of installing JasPer.
The INSTALL doc mentions an arch specific
cmake
option to use native GLUT on Mac OS: