开发者

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

开发者 https://www.devze.com 2023-03-03 21:51 出处:网络
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.

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


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

-framework GLUT


Slight correction in your code:

j = rand() % 3;

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消