macos 架构 x86_64 的未定义符号:“_glutInit”,引用自:main.o 中的 _main / Mac 上的 Netbeans

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5925697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:02:52  来源:igfitidea点击:

Undefined symbols for architecture x86_64:"_glutInit", referenced from:_main in main.o / Netbeans on Mac

macosopenglnetbeans

提问by Andreu Boada de Atela

I′m a beginner with OpenGL and "my" first 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.

我是 OpenGL 的初学者,“我的”第一个程序就是这个谢尔宾斯基垫片。我在 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();
}


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

体系结构 x86_64 的未定义符号:

“_glutInit”,引用自:

 _main in main.o

“_glutInitDisplayMode”,引用自:

 _main in main.o

“_glutInitWindowSize”,引用自:

 _main in main.o

“_glutInitWindowPosition”,引用自:

 _main in main.o

“_glutCreateWindow”,引用自:

 _main in main.o

“_glutDisplayFunc”,引用自:

 _main in main.o

“_glutMainLoop”,引用自:

 _main in main.o

ld:找不到架构 x86_64 的符号

collect2: ld 返回 1 个退出状态

make[2]: *[dist/Debug/GNU-MacOSX/sierpinski] 错误 1

make[1]: *[.build-conf] 错误 2

制作:*[.build-impl] 错误 2

回答by

You need to link the GLUT framework. In Project Properties > Linker > Command Line > Aditional Options, specify

您需要链接 GLUT 框架。在项目属性 > 链接器 > 命令行 > 附加选项中,指定

-framework GLUT

回答by Randhir Singh

Slight correction in your code:

稍微更正您的代码:

j = rand() % 3;

and not rand() * 3;. That gives seg fault for obvious reasons.

而不是rand() * 3;。由于显而易见的原因,这会导致段错误。