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

发布于 2024-11-06 09:07:56 字数 1917 浏览 3 评论 0原文

我的程序是这个谢尔宾斯基垫片。我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花伊自在美 2024-11-13 09:07:56

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

-framework GLUT

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

-framework GLUT
怪我入戏太深 2024-11-13 09:07:56

对代码进行轻微修正:

j = rand() % 3;

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

Slight correction in your code:

j = rand() % 3;

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

枫林﹌晚霞¤ 2024-11-13 09:07:56

在安装 JasPer 的上下文中补充 @user55721 的 GLUT 框架答案。

INSTALL 文档提到了一个特定于架构的 cmake 选项,用于在 Mac OS 上使用 native GLUT:

在 Mac OSX 下构建 JasPer 软件时,仅使用
官方支持 OpenGL 原生框架。如果自由过剩
库已安装在您的系统上,您需要确保
本机 GLUT 库(与 Freeglut 库相对)由
构建过程。这可以通过添加额外的选项来完成
到类似于以下内容的 cmake 命令行:

-DGLUT_glut_LIBRARY=/System/Library/Frameworks/GLUT.framework

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:

When building the JasPer software under Mac OSX, only the use of the
native framework for OpenGL is officially supported. If the Freeglut
library is installed on your system, you will need to ensure that the
native GLUT library (as opposed to the Freeglut library) is used by
the build process. This can be accomplished by adding an extra option
to the cmake command line that resembles the following:

-DGLUT_glut_LIBRARY=/System/Library/Frameworks/GLUT.framework
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文