ld在Linux上不链接OpenGL [英] ld does not link OpenGL on Linux

查看:89
本文介绍了ld在Linux上不链接OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc -lGL -lGLU -lglut light.c 
/tmp/ccfuthSi.o: In function `init':
light.c:(.text+0x72): undefined reference to `glClearColor'
light.c:(.text+0x7e): undefined reference to `glShadeModel'
light.c:(.text+0x99): undefined reference to `glMaterialfv'
light.c:(.text+0xb4): undefined reference to `glMaterialfv'
light.c:(.text+0xcf): undefined reference to `glLightfv'
light.c:(.text+0xdb): undefined reference to `glEnable'
light.c:(.text+0xe7): undefined reference to `glEnable'
light.c:(.text+0xf3): undefined reference to `glEnable'
/tmp/ccfuthSi.o: In function `display':
light.c:(.text+0x107): undefined reference to `glClear'
light.c:(.text+0x121): undefined reference to `glutSolidSphere'
light.c:(.text+0x126): undefined reference to `glFlush'
/tmp/ccfuthSi.o: In function `reshape':
light.c:(.text+0x150): undefined reference to `glViewport'
light.c:(.text+0x15c): undefined reference to `glMatrixMode'
light.c:(.text+0x161): undefined reference to `glLoadIdentity'
light.c:(.text+0x1bf): undefined reference to `glOrtho'
light.c:(.text+0x217): undefined reference to `glOrtho'
light.c:(.text+0x223): undefined reference to `glMatrixMode'
light.c:(.text+0x228): undefined reference to `glLoadIdentity'
/tmp/ccfuthSi.o: In function `main':
light.c:(.text+0x268): undefined reference to `glutInit'
light.c:(.text+0x274): undefined reference to `glutInitDisplayMode'
light.c:(.text+0x288): undefined reference to `glutInitWindowSize'
light.c:(.text+0x29c): undefined reference to `glutInitWindowPosition'
light.c:(.text+0x2a9): undefined reference to `glutCreateWindow'
light.c:(.text+0x2ba): undefined reference to `glutDisplayFunc'
light.c:(.text+0x2c6): undefined reference to `glutReshapeFunc'
light.c:(.text+0x2d2): undefined reference to `glutKeyboardFunc'
light.c:(.text+0x2d7): undefined reference to `glutMainLoop'

如您所见,我将所需的参数传递给了gcc.为什么不起作用? Linux Mint 12.

As you can see, i pass the required parameters to the gcc. Why it does not work? Linux Mint 12.

推荐答案

这确实是一个FAQ(在这里已被多次询问和回答).链接时,参数顺序很重要.图书馆应排在最后(并保持良好状态).您应该运行

It really is a FAQ (and has been asked and answered many times here). Order of arguments matters when linking. Libraries should go last (and in the good order). You should run

gcc -Wall -g light.c -lGL -lGLU -lglut -o light 

这篇关于ld在Linux上不链接OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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