简体   繁体   English

在c ++中链接标头

[英]Linking headers in c++

im new with gcc.I dont know what i do bad when i write the command line to compiling. 我是新的gcc.I不知道当我编写命令行编译时我做坏了。 i have 3 files, 2 .cpp and 1 .h ,the first lines of my files: 我有3个文件,2 .cpp和1 .h,我文件的第一行:

main.cpp 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 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 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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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