在Mac上编译OpenGL错误:架构x86_64的未定义符号:

时间:2012-11-24 18:26:32

标签: xcode opengl compilation

我正在尝试使用Xcode在Mac上编译一个简单的OpenGL代码。以前我用过Windows。我遇到了一些我根本不知道的错误。有人可以帮忙修复。

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>

void display (void)
{
    glColor3f ( 1.0, 1.0, 1.0 );

    float angles[20] = {     30.0,45.0,60.0,75.0,90.0,105.0,120.0,135.0,150.0,165.0,180.0,195.0,210.0,225.0,240.0,255.0,270.0,285.0,300.0 };

int i; float xOut, yOut, xIn, yIn; const float pi = 3.141592;
for ( i = 0; i == 19; i++ )
{
    float angle = angles[i]*pi/180.0;
    glBegin ( GL_LINE );
    xOut = 12 * sinf(angle);
    yOut = 12 * cosf(angle);
    xIn  =  9 * sinf(angle);
    yIn  =  9 * cosf(angle);
    glVertex3f ( xOut, yOut, 0.0);
    glVertex3f (  xIn,  yIn, 0.0);
    glEnd();

}

glutSwapBuffers();
}

void initializeWindow (void)
{

glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);

glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
glOrtho ( -100.0, 100.0, -100.0, 100.0, -1.0, 1.0);

}


int main(int argc, char** argv)
{
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize ( 500, 500 );
glutInitWindowPosition ( 100, 100 );
glutCreateWindow ( "PrimaryFlightDisplay" );

initializeWindow ();

glutDisplayFunc ( display );

glutMainLoop ();

return 0;

}

使用

在终端编译时出现这些错误
gcc -o main main.cpp -framework GLUT -framework OpenGL

"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cczuL03z.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cczuL03z.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

1 个答案:

答案 0 :(得分:1)

使用“g ++”代替“gcc”。这将链接到C ++运行时。