我是gcc的新手。我不知道在编写命令行时我做错了什么。 我有3个文件,2 .cpp和1 .h,我文件的第一行:
的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)
我使用此命令行进行编译:
g++ main.cpp -lglut -lGL -o eject
并显示此错误:
/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)'
答案 0 :(得分:2)
g++ -c main.cpp function.cpp
编译两个文件(这将生成目标文件main.o
和function.o
),然后
要g++ -lglut -lGL main.o function.o -o eject
链接。