在 Eclipse 中构建 FLTK 项目

发布于 2024-08-04 09:37:03 字数 2345 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如此安好 2024-08-11 09:37:04

Scott,不幸的是 FLTK 1.x 没有提供(至少我上次检查时没有)来自 FLTK2 分支的优秀 fltk2-config 脚本,您可以像这样调用它:

fltk2-config --use-gl --ldflags

并且输出可能是:

-Wl,-rpath,/usr/lib -lfltk2_gl -lGLU -lGL -lfltk2 -lX11 -lXi -lXinerama -lXft -ldl -lpthread -lm -lXext

所以,我相信 FLTK 1.x 应用程序的 LDFLAGS 是:

-Wl,-rpath,/usr/lib -lfltk_gl -lGLU -lGL -lfltk -lX11 -lXi -lXinerama -lXft -ldl -lpthread -lm -lXext

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:

fltk2-config --use-gl --ldflags

And the output may be:

-Wl,-rpath,/usr/lib -lfltk2_gl -lGLU -lGL -lfltk2 -lX11 -lXi -lXinerama -lXft -ldl -lpthread -lm -lXext

So, I believe the LDFLAGS for a FLTK 1.x application would be:

-Wl,-rpath,/usr/lib -lfltk_gl -lGLU -lGL -lfltk -lX11 -lXi -lXinerama -lXft -ldl -lpthread -lm -lXext
天赋异禀 2024-08-11 09:37:03

您检查过“基本示例”一章吗?

您可能需要告诉编译器在哪里可以找到包含所有头文件的目录“fltk”。这通常是使用添加到编译器行的 -I 选项来完成的:

c++ -I/usr/local/include ...

同样,在链接应用程序时,您需要告诉编译器使用 FLTK 库以及在哪里可以找到它。在 X 中,您需要包含 fltk 调用的几个库:

c++ ... -L/usr/local/lib -lfltk2 -lXext -lXinerama -lXft -lX11 -lXi -lm

在您的情况下,可能并非 FL 的所有标头定义都在 /usr/include/FL 中:可能在其他地方有一些。

Did you check the chapter "Basic Example"?

You will probably need to tell the compiler where to find the directory "fltk" with all the header files. This is usually done using the -I option added to the compiler line:

c++ -I/usr/local/include ...

Similarly, when linking your application you will need to tell the compiler to use the FLTK library and where to find it. In X you need to include several libraries that fltk calls:

c++ ... -L/usr/local/lib -lfltk2 -lXext -lXinerama -lXft -lX11 -lXi -lm

In your case, may be not all the header definitions of FL are in /usr/include/FL: there may be some elsewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文