当我在c中编译一个程序时,为什么会得到一个未定义的引用(例如`glColor3f')? [英] Why do I get an undefined reference( to `glColor3f' ,for example) when I compile a program in c?

查看:1566
本文介绍了当我在c中编译一个程序时,为什么会得到一个未定义的引用(例如`glColor3f')?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译一个在ubuntu(linux)中使用opengl的示例程序。代码的一小段代码如下:

  #include< stdlib.h> 

#include< GL / glut.h>


void createBox(GLfloat centroX,GLfloat centroY,
GLfloat corr,GLfloat corG,GLfloat corB)
{
/ * Cor * /

glColor3f(corR,corG,corB);

我已经安装了所有要在opengl中开发的软件包(在ubuntu中),即: p>

  freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa 
libglu1-mesa-dev libgl1-mesa- glx libgl1-mesa-dev

我编译这样的例子:

  gcc -lGL CG_ex04.c -o main 

,我得到以下内容:
$ b $ pre $ /tmp/ccDWmJDZ.o:函数`createBox':
CG_ex04.c :(。text + 0x31):未定义引用'glColor3f'

等错误



有人知道我在做什么错吗? 。

解决方案

尝试 gcc -o main CG_ex4.c -lGL 。 gcc参数的正确顺序很重要。

I'm compiling an example program that uses opengl in ubuntu (linux). A short snippet of the code is the following:

 #include <stdlib.h> 

 #include <GL/glut.h>


 void createBox( GLfloat centroX, GLfloat centroY,
                       GLfloat corR, GLfloat corG, GLfloat corB )
 {
    /* Cor  */

    glColor3f( corR, corG, corB );

I've installed all of the packages to develop in opengl (in ubuntu), namely:

freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa
libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev

I compile the example like this:

gcc -lGL   CG_ex04.c -o main

and I get the following

/tmp/ccDWmJDZ.o: In function `createBox':
CG_ex04.c:(.text+0x31): undefined reference to `glColor3f'

and other errors along the same line.

Does anyone know what I'm doing wrong?

Thanx in advance for any help.

解决方案

Try gcc -o main CG_ex4.c -lGL. The correct order of gcc parameters is important.

这篇关于当我在c中编译一个程序时,为什么会得到一个未定义的引用(例如`glColor3f')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆