简体   繁体   中英

Linking headers in c++

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)'

g++ -c main.cpp function.cpp用于编译两个文件(这将生成目标文件main.ofunction.o ),然后g++ -lglut -lGL main.o function.o -o eject to link。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM