views:

432

answers:

1

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.

A: 

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.

VonC