[SOLVED] How to use glut in my shared library



  • Hi everyone, I got a problem with using glut in my shared library. Please help me!
    I'm developing an application that draws 3D solid in a QWidget, I use glut library to initial, draw and so on... And the app works with no problem, but after a month, I realize bulding entire app is too slow, it take about 15 minutes for 1 build, so I decided to break my app into separate libraries to reduce the building time.
    It's ok with libraries doesn't include glut, but with glut included in my library, it can't compile, with
    @
    error: undefined reference to glBegin@4' error: undefined reference toglVertex3f@12'
    error: undefined reference to `glEnd@0'
    @
    Here is my library project:
    util.pro file:

    @
    LIBS += -L./lib -lglut32 #glut.lib, glut32.lib, libglut32.a here
    INCLUDEPATH += ./include #glut.h file here

    TARGET = util
    TEMPLATE = lib

    SOURCES += draw.cpp
    HEADERS += draw.h
    @
    Here is draw.h file:
    @
    void drawLine(float x1, float y1, float z1, float x2, float y2, float z2);
    @
    And draw.cpp file:
    @
    #include <glut.h>
    #include "draw.h"
    void drawLine(float x1, float y1, float z1, float x2, float y2, float z2){
    glBegin(GL_LINES);
    glVertex3f(x1,y1,z1);
    glVertex3f(x2,y2,z2);
    glEnd();
    }
    @
    I also try to use static library but it isn't work either.
    So how to use glut with static or shared library? Is it posible with qt?

    Any suggest will be appreciated!

    [Edit: Added @ tags for code formatting -- mlong]



  • The missing symbols do not come from GLUT but from OpenGL itself. You should add the OpenGL library as well in your LIBS.



  • Which may be as simple as doing QT += opengl in your subprojects by the way.



  • Thanks rcari & Don Harris so much!
    Finally, I can use glut in my library with your help.



  • Would this work with QT 5 as well



  • Would this work with QT 5 as well


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.