About this blog

Welcome to Ha Le's Work and Research Blog. This page contains information and experience that I've collected during my college's years and other work experience. The topics included are Software development (C++ mainly), Robotics Technology and other related fields.

Search This Blog

Saturday, February 13, 2010

OpenCascade and Qt Integration in Windows and Linux (Part 2)

On Unix, things get a bit more complicated. The following process was successful on Ubuntu 9.

1. Download OpenCascade source code (.tgz) and other packages required, for Qt, download the SDK for Linux.

2. make sure you have: build-essential, autoconf, automake1.7,  cpp-4.4, , gcc, gcc-4.4,g++, g++-4.4, java-common, libc* (i.e. libc-dev-bin), libgc*, libgcj*,libgl1-mesa*,libglu1-mesa,libgnome*,libgtk*,sun-java6*,x11*,xorg-dev,xserver-xorg* ,libsdl*
  • For those don't know, it can be done by sudo apt-get install "name of package"
  • If you don't want to bother download all these things, and you have plenty of space in your hard drive ( I used up 15Gb to get this all working), you can use this file and type into your terminal : "dpkg --set-selections < installed-software ", then, followed by "dselect". (installed-software is the filename you've downloaded).
3. Install the packages in the order Tcl, Tk, Tix, Fltk (./configure && make && sudo make install). \
4. Qt can be installed in parallel with the above package, it comes in .bin file so you have to follow (in the directory with the downloaded  ".bin"
  • chmod +x qt....(filename).bin ----------------- ENTER
  • ./qt............filename.bin
  • This would execute the installation and ... like Windows.
5. Configure OpenCascade, you HAVE TO follow the Readme.txt in OpenCascade6.3.0/ros/Readme.txt to properly configure OpenCascade, my Configure looks like this
./configure $flags --with-java-include=/usr/lib/jvm/java-6-sun-1.6.0.15/include --prefix=$INSTALL_DIR
  • to have INSTALL_DIR you need to type in these BEFORE configure
    • INSTALL_DIR=/home//.... (whatever directory you want to install OCC to)
    • in your terminal, to check type" echo $INSTALL_DIR".
  • If you install Tcl, tk etc. as default, OCC will be able to find them, as well as X11 so you don't need to specify the path. But for some reason you need to specify Java's path, it's where the file jni.h is so you can find it by "locate jni.h" (make sure you update your database first by: " sudo updatedb"
  • Take time and follow the configure procedure, if something is not right, recommendedly to "make distclean" to restart from fresh. If packages missing, check the file "installed-software" above for what I needed to get mine working
6. DON'T TYPE "MAKE" yet!!!!!!
  • Gcc4.4 somehow treats one line of code in OCC as error, so you need to fix it before making
  • Type "locate WOKUnix_FDescr.cxx" to get to that file
  • type "gedit WOKUnix_FDescr.cxx" to edit that file
  • Go to LINE 205  which has
  •  myFileChannel = open(apath.ToCString(),  O_RDONLY | O_NDELAY | O_CREAT);
  • and change that into
  • myFileChannel = open(apath.ToCString(),  O_RDONLY | O_NDELAY | O_CREAT,0664);
7. Now you can "make && sudo make install"

8. After installation, you need to add some environment variable refer to OCC and use them in your program.
To add environment variable, read this
  • I myself use /etc/environment (type "sudo gedit /etc/environment") 
  • add CASROOT="/home/ha/OpenCascade" 
  • and LD_LIBRARY_PATH="$CASROOT/Linux/lib"
  • to the end of the file, then you can use $(CASROOT)/Linux/lib (or LD_LIBRARY_PATH) to refer to your library or $(CASROOT)/inc to refer to your includes etc.
(Need to restart for this to take effect)

9. Particularly for Qt Creator, to use OCC library, in the project file .pro, specify these

INCLUDEPATH += ./GeneratedFiles \
    ./GeneratedFiles/Debug \
    $$(CASROOT)/inc   \

LIBS += -L$$(CASROOT)/Linux/lib \
    -lTKernel \
    -lTKGeomBase \
    -lTKTopAlgo \
    -lTKOffset \
    -lTKBool \
    -lTKPrim \
    -lTKFillet \
..(whatever library you want to use)

10. If there's runtime error due to missing library, go to Projects (in the QtCreator main page) in tab run, choose environment variable add/edit, there you can check if the environment vars are correct and edit if you see that the library path is missing.

Now you should be able to compile and run a Qt-OpenCascade program

I've included my .pro and .pri file so you can use that as examples



1 comment:

  1. Please download qt-addin for VS here so qt project can be used
    http://qt.nokia.com/downloads/visual-studio-add-in

    ReplyDelete