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

Showing posts with label cross-platform. Show all posts
Showing posts with label cross-platform. Show all posts

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



OpenCascade and Qt Integration in Windows and Linux

In my COHESIVE project, it comes to the decision of using OpenCascade as the framework for modelling and visualizing, cos it's powerful enough for our application and... free to use, and Qt as the UI development libraries due to their powerful, cross-platform tools and fantastic documentation.

My project requires the software to be cross-platform (Windows and Unix), therefore the installtion and compilation of the two libraries on both platforms is definitely the start.... But, it's not that easy....So I write this post to help those who want to use the two libraries together cross-platform.

This guide is according to my notes which is already a month old, so it might not contain all steps needed, but I'm pretty positive that it covers at least 90% of what needs to be done.... if you find error, please report here, I might be able to figure out.

1. On Windows (tested on Windows 7 and Xp)
Very easy.

  • Download OpenCascade for Windows and install.
  • Download and install MS Visual C++ Express 2008 (Free). 
  • Download Qt-OPENSOURCE for Windows and compile with VS2008 as here
  • NOTE: the Qt Creator SDK will NOT work with OpenCascade library due to it was compiled by Visual C++ while Qt SDK uses MinGW. I've tried and failed to compile OpenCascade source using MinGW, if you can, that'd be awesome if you can share.
  • Make sure you add in the following to includeyour VC++ Project properties Tools-Options-Projects and Solutions - VC++ Directories 
    • For "include file": add $(PATH)\include and $(CASROOT)\inc 
    • For Library File: add $(CASROOT)\win32\libd
    • Above assumed you used standard installation procedure for OpenCascade and Qt.
    • Make sure environment variable $PATH has the following, it might be overkilled but it worked for me, you can eliminate some if you want C:\OpenCASCADE6.3.0\ros\win32\libd;C:\OpenCASCADE6.3.0\ros;\Qt\4.6.1\bin;C:\OpenCASCADE6.3.0\3rdparty\win32\vs;C:\OpenCASCADE6.3.0\3rdparty\win32\tcltk\bin;C:\OpenCASCADE6.3.0\ros\win32\bin
    • $(CASROOT) should already be set to C:\OpenCASCADE6.3.0\ros\

  • Before compiling, make sure your linker knows it needs OpenCascade Library (VS) Projects--Properties--Configuration Properties -- Linker -- Input 
    • Then aat Additional Dependency, make sure you have (if not, just add), this again might be overkilled... but worked
    • TKernel.lib
    • TKGeomBase.lib
    • TKTopAlgo.lib
    • TKOffset.lib
    • TKBool.lib
    • TKPrim.lib
    • TKFillet.lib
    • odbc32.lib
    • odbccp32.lib
    • TKMath.lib
    • TKService.lib
    • TKV3d.lib
    • TKBrep.lib
    • TKIGES.lib
    • PTKernel.lib
    • TKSTL.lib
    • TKVRML.lib
    • TKSTEP.lib
    • TKShapeSchema.lib
    • TKG3d.lib
    • TKG2d.lib
    • TKXSBase.lib
    • TKPShape.lib
    • TKShHealing.lib
    • TKBO.lib
    • qtmaind.lib
    • QtCored4.lib
    • QtGuid4.lib
    • QtOpenGLd4.lib
    • opengl32.lib
    • glu32.lib
    • Qt3Supportd4.lib
    • comdlg32.lib
    • QtTestd4.lib

  • You should be able to compile and run the "Tutorial" code comes with OpenCascade in VS2008 and see how it works.
  • To be continued