在 Eclipse 中构建 FLTK 项目
我在 Eclipse 中设置 FLTK 时遇到问题。我正在尝试使用以下代码创建一个 OpenGL 窗口(我在此处找到) :
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
//
// Simple resizable 2D GL window
// erco 10/08/05
//
class MyGlWindow : public Fl_Gl_Window {
// DRAW METHOD
// OpenGL window: (w,h) is upper right, (-w,-h) is lower left, (0,0) is center
//
void draw() {
// First time? init viewport, etc.
if (!valid()) {
valid(1);
glLoadIdentity();
glViewport(0,0,w(),h());
glOrtho(-w(),w(),-h(),h(),-1,1);
}
// Clear screen
glClear(GL_COLOR_BUFFER_BIT);
// Draw white 'X'
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); glEnd();
glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); glEnd();
}
// HANDLE WINDOW RESIZING
// If window reshaped, need to readjust viewport/ortho
//
void resize(int X,int Y,int W,int H) {
Fl_Gl_Window::resize(X,Y,W,H);
glLoadIdentity();
glViewport(0,0,W,H);
glOrtho(-W,W,-H,H,-1,1);
redraw();
}
public:
// CONSTRUCTOR
MyGlWindow(int X,int Y,int W,int H,const char*L=0) : Fl_Gl_Window(X,Y,W,H,L) {
}
};
// MAIN
int main() {
Fl_Window win( 500, 300);
MyGlWindow mygl(10, 10, win.w()-20, win.h()-20);
win.resizable(mygl);
win.show();
return(Fl::run());
}
以下是发出的命令:
make -k all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/FL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Experiment01
Invoking: GCC C++ Linker
g++ -L/usr/lib -o"Experiment01" ./main.o -lGL -lfltk
以下是错误:
/usr/include/FL/Fl_Gl_Window.H undefined reference to `Fl_Gl_Window::init()'
/usr/include/FL/Fl_Gl_Window.H undefined reference to `vtable for Fl_Gl_Window'
undefined reference to `Fl_Gl_Window::~Fl_Gl_Window()'
undefined reference to `Fl_Gl_Window::resize(int, int, int, int)'
我还需要链接什么?我尝试过 -llibfltk.so -llibfltk_gl.so 等,但总是说找不到指定的库。
I am having trouble getting set up with FLTK in Eclipse. I am trying to create an OpenGL window with the following code (which I found here):
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
//
// Simple resizable 2D GL window
// erco 10/08/05
//
class MyGlWindow : public Fl_Gl_Window {
// DRAW METHOD
// OpenGL window: (w,h) is upper right, (-w,-h) is lower left, (0,0) is center
//
void draw() {
// First time? init viewport, etc.
if (!valid()) {
valid(1);
glLoadIdentity();
glViewport(0,0,w(),h());
glOrtho(-w(),w(),-h(),h(),-1,1);
}
// Clear screen
glClear(GL_COLOR_BUFFER_BIT);
// Draw white 'X'
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); glEnd();
glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); glEnd();
}
// HANDLE WINDOW RESIZING
// If window reshaped, need to readjust viewport/ortho
//
void resize(int X,int Y,int W,int H) {
Fl_Gl_Window::resize(X,Y,W,H);
glLoadIdentity();
glViewport(0,0,W,H);
glOrtho(-W,W,-H,H,-1,1);
redraw();
}
public:
// CONSTRUCTOR
MyGlWindow(int X,int Y,int W,int H,const char*L=0) : Fl_Gl_Window(X,Y,W,H,L) {
}
};
// MAIN
int main() {
Fl_Window win( 500, 300);
MyGlWindow mygl(10, 10, win.w()-20, win.h()-20);
win.resizable(mygl);
win.show();
return(Fl::run());
}
Here are the commands being issued:
make -k all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/FL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Experiment01
Invoking: GCC C++ Linker
g++ -L/usr/lib -o"Experiment01" ./main.o -lGL -lfltk
And here are the errors:
/usr/include/FL/Fl_Gl_Window.H undefined reference to `Fl_Gl_Window::init()'
/usr/include/FL/Fl_Gl_Window.H undefined reference to `vtable for Fl_Gl_Window'
undefined reference to `Fl_Gl_Window::~Fl_Gl_Window()'
undefined reference to `Fl_Gl_Window::resize(int, int, int, int)'
What else do I need to link? I've tried -llibfltk.so -llibfltk_gl.so, etc., but it always says that it cannot find the specified library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Scott,不幸的是 FLTK 1.x 没有提供(至少我上次检查时没有)来自 FLTK2 分支的优秀
fltk2-config
脚本,您可以像这样调用它:并且输出可能是:
所以,我相信 FLTK 1.x 应用程序的 LDFLAGS 是:
Scott, unfortunately FLTK 1.x does not provide (at least the last time I checked it did not) the excellent
fltk2-config
script from the FLTK2 branch, which you can invoke like:And the output may be:
So, I believe the LDFLAGS for a FLTK 1.x application would be:
您检查过“基本示例”一章吗?
在您的情况下,可能并非 FL 的所有标头定义都在
/usr/include/FL
中:可能在其他地方有一些。Did you check the chapter "Basic Example"?
In your case, may be not all the header definitions of FL are in
/usr/include/FL
: there may be some elsewhere.