我如何与 GLU 链接? [英] How do I link with GLU?

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

问题描述

我刚刚发现了 FLTK,并为我的测试制作了一个 makefile.这是我的生成文件:

<预><代码>################ 模板生成文件############### 我们不知道在这台机器上使用什么编译器来构建 fltk - 但是 fltk-config 确实......CC = $(shell fltk-config --cc)CXX = $(shell fltk-config --cxx)# 为编译器设置标志:fltk-config 知道基本设置,然后我们可以添加自己的...CFLAGS = $(shell fltk-config --cflags)CXXFLAGS = $(shell fltk-config --cxxflags) -I/System/Library/Frameworks/OpenGL.framework/Versions/A/# 我们不知道要链接哪些库:fltk-config 会做.... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LINKFLTK = $(shell fltk-config --ldstaticflags)LINKFLTK_GL = $(shell fltk-config --use-gl --ldstaticflags) -lGLULINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags)# 链接后可能运行的步骤...STRIP = 条带POSTBUILD = fltk-config --post # 在 OSX 上是必需的,在其他平台上什么都不做,所以调用很安全目标 = 完成文件# 定义目标应用程序的名称全部:$(目标)# 定义如何构建各种目标文件... -snip-# 现在定义如何链接最终的应用程序 - 假设它需要图像和 OpenGL 支持$(TARGET): MyWindow.o main.o$(CXX) -o $@ MyWindow.o main.o $(LINKFLTK_IMG) $(LINKFLTK_GL)$(STRIP) $@$(POSTBUILD) $@ # 仅在 OSX 上需要,但为了可移植性还是调用它##############结束#################

(这里是目标文件代码:)

main.o: main.cpp MyWindow.h main.h$(CXX) -c $<\$(CXXFLAGS)

MyWindow.o: MyWindow.cpp MyWindow.h$(CXX) -c $<\$(CXXFLAGS)

这是它给我的错误:

在 MyWindow.cpp:10 包含的文件中:MyWindow.h:14:20: 错误: GL/glu.h: 没有那个文件或目录MyWindow.cpp:在成员函数‘virtual void MyWindow::draw()’中:MyWindow.cpp:49: 错误: 'gluPerspective' 未在此范围内声明make: * [MyWindow.o] 错误 1

(代码无关)

解决方案

根据您使用的 fltk 版本,它有一些自己的 openGL 标头.我将以下行添加到我的包含库中:-lfltk -lfltk_gl -lGL -lGLU

矫枉过正,但它完成了工作.

I've just discovered FLTK and I made a makefile for my test. Here is my makefile:


################ template makefile ##############
# We don't know what compiler to use to build fltk on this machine - but fltk-config does...
CC  = $(shell fltk-config --cc)
CXX = $(shell fltk-config --cxx)

# Set the flags for compiler: fltk-config knows the basic settings, then we can add our own...
CFLAGS   = $(shell fltk-config --cflags)
CXXFLAGS = $(shell fltk-config --cxxflags) -I/System/Library/Frameworks/OpenGL.framework/Versions/A/

# We don't know what libraries to link with: fltk-config does...
LINKFLTK = $(shell fltk-config --ldstaticflags)
LINKFLTK_GL = $(shell fltk-config --use-gl --ldstaticflags) -lGLU
LINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags)

# Possible steps to run after linking...
STRIP      = strip
POSTBUILD  = fltk-config --post # Required on OSX, does nothing on other platforms, so safe to call
TARGET     = CompletedFile

# Define what your target application is called
all: $(TARGET)

# Define how to build the various object files... -snip-

# Now define how to link the final app - let's assume it needs image and OpenGL support
$(TARGET): MyWindow.o main.o 
        $(CXX) -o $@ MyWindow.o main.o  $(LINKFLTK_IMG) $(LINKFLTK_GL)
        $(STRIP) $@
        $(POSTBUILD) $@  # only required on OSX, but call it anyway for portability

############### end #################

(Heres the object file code:)

main.o: main.cpp MyWindow.h main.h 
        $(CXX) -c $< \
            $(CXXFLAGS)

MyWindow.o: MyWindow.cpp MyWindow.h $(CXX) -c $< \ $(CXXFLAGS)

Here is the error it gives me:

In file included from MyWindow.cpp:10:
MyWindow.h:14:20: error: GL/glu.h: No such file or directory
MyWindow.cpp: In member function ‘virtual void MyWindow::draw()’:
MyWindow.cpp:49: error: ‘gluPerspective’ was not declared in this scope
make: * [MyWindow.o] Error 1

(The code is irrelevant)

解决方案

Depending on the fltk version you are using it has some of it's own openGL headers. I add the following lines to my include libraries: -lfltk -lfltk_gl -lGL -lGLU

Overkill but it gets the job done.

这篇关于我如何与 GLU 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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