Frage

im new with gcc.I dont know what i do bad when i write the command line to compiling. i have 3 files, 2 .cpp and 1 .h ,the first lines of my files:

main.cpp

#define GLUT_DISABLE_ATEXIT_HACK
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "GL/glut.h"
#include "Funciones.h"

using namespace std;

int main(int argc, char **argv)

function.h

void init_scene();
void render_scene();
GLvoid initGL();
GLvoid window_display();
GLvoid window_reshape(GLsizei width, GLsizei height);
GLvoid window_key(unsigned char key, int x, int y);
GLvoid callback_special(int key, int x, int y);
GLvoid callback_mouse(int button, int state, int x, int y);
GLvoid callback_motion(int x, int y);
int CvtoGLx(int n);
int CvtoGLy(int n);
//function called on each frame
GLvoid window_idle();

function.cpp

#include "Funciones.h"
#include "GL/Glut.h"

GLvoid callback_special(int key, int x, int y)

i use this command line to compile :

g++ main.cpp -lglut -lGL -o eject

and this display this error:

/tmp/cceLFOgn.o:test1.cpp:function main: error: undefined reference to 'initGL()'
/tmp/cceLFOgn.o:test1.cpp:function main: error: undefined reference to 'init_scene()'
/tmp/cceLFOgn.o:test1.cpp:function main: error: undefined reference to 'window_display()'
/tmp/cceLFOgn.o:test1.cpp:function main: error: undefined reference to 'window_reshape(int, int)'
/tmp/cceLFOgn.o:test1.cpp:function main: error: undefined reference to 'window_key(unsigned char, int, int)'
War es hilfreich?

Lösung

g++ -c main.cpp function.cpp to compile both files (this will produce object files main.o and function.o), then g++ -lglut -lGL main.o function.o -o eject to link.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top