FreeGLUT在Linux中链接问题 [英] FreeGLUT linking Issues in Linux

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

问题描述

我正在运行 Linux Mint 14.1 64位

我安装了以下lib:

mesa-common-dev,
freeglut3-dev,
libglew-dev

这是我的包含,位于我的 Main.h 文件中:

Here are my includes, located in my Main.h file:

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>

#include <GL/glew.h>
#include <GL/glut.h>
#include <time.h> 

我检查了libs安装是否正确,它们似乎位于 / usr / lib / x86_64-linux-gnu
/ usr / include / GL

I checked that the libs installed correctly, they seem to be located in /usr/lib/x86_64-linux-gnu and the headers in /usr/include/GL

具有以下标志的 Main.C 文件:

g++ -Wall -Wextra -Weffc++ -Winit-self -Wmissing-include-dirs -Wswitch-default -switch-enum -Wunused-parameter -Wstrict-overflow=5 -Wfloat-equal -Wshadow -Wc++0x-compat -Wconversion -Wsign-conversion -Wmissing-declarations -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo -Werror -pedantic -Wcast-qual -fno-pretty-templates -fmessage-length=80 -fdiagnostics-show-option -g -std=c++0x -pipe -frepo -c  Main.C -o Main.o

Main.o 生成没有任何问题,然后我尝试创建二进制:

Main.o is generated without any issues, then I try to create the binary:

g++  -I/usr/include -L/usr/lib/x86_64-linux-gnu -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng Main.o -o main

并收到以下错误:

Main.o: In function `init()':
/path/to/Main.C:12: undefined reference to `glClearColor'
Main.o: In function `initGLUT(int, char**)':
/path/to/Main.C: undefined reference to `glutInit'
/path/to/Main.C:21: undefined reference to `glutInitDisplayMode'
/path/to/Main.C:24: undefined reference to `glutInitWindowSize'
/path/to/Main.C:25: undefined reference to `glutCreateWindow'
/path/to/Main.C:28: undefined reference to `glutDisplayFunc'
/path/to/Main.C:31: undefined reference to `glutKeyboardFunc'
/path/to/Main.C:34: undefined reference to `glutMouseFunc'
/path/to/Main.C:37: undefined reference to `glutReshapeFunc'
/path/to/Main.C:40: undefined reference to `glutIdleFunc'
Main.o: In function `printFPS()':
/path/to/Main.C:96: undefined reference to `glutGet'
Main.o: In function `reshape(int, int)':
/path/to/Main.C:123: undefined reference to `glutPostRedisplay'
Main.o: In function `getTime()':
/path/to/Main.C:129: undefined reference to `glutGet'
Main.o: In function `idle()':
/path/to/Main.C:141: undefined reference to `glutPostRedisplay'
Main.o: In function `display()':
/path/to/Main.C:148: undefined reference to `glClearColor'
/path/to/Main.C:149: undefined reference to `glClear'
/path/to/Main.C:150: undefined reference to `glFlush'
/path/to/Main.C:151: undefined reference to `glutSwapBuffers'
Main.o: In function `main':
/path/to/Main.C:164: undefined reference to `glutMainLoop'

程序编译和链接在另一个Linux系统上。
我可能会遗漏什么?

The program compiles and links on another Linux system though. what could I be missing?

推荐答案

p>

You have to pass the libraries last (after the object file)

g++  -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o \
  -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main

原因后面是,链接器只链接当前未定义的符号。如果在目标文件之前传递库,那么没有任何未定义的符号被链接,因此编译/链接将失败。

The reason behind this is, that the linker only links symbols, that are currently undefined. If you pass the libraries before the object files, then there aren't any undefined symbols to be linked and compilation/linking will therefore fail.

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

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