Introduction
This document will serve as a guide to compile OpenSG on different platforms. We have successfully compiled it on Mac, Linux and Windows (Win being the most troublesome).
I am personally working on a Linux (Xubuntu) based machine, but other programmers helping me are working on Windows and Mac. This doc will serve as dump for all the tweaking we had to do with our code to get it working properly on the different platforms we are working on.
Google Docs link to this document: http://docs.google.com/View?id=dgz9dtmx_18mrv63dcc
Building on Linux
Standard instructions worked for me for normal build with glut.
Building on MacOS
Standard instructions worked for me for normal build with glut.
Building on Windows with VisualStudio
Follow the guide on http://opensg.vrsource.org/trac/wiki/BuildVS2005Cygwin
We needed to tweak the process a bit to get it working
- Make sure you have tar, unzip in addition to the ones mentioned in the above link.
- Use tar cmd on cygwin to unzip the OpenSG source. Using other unzpping softwares will cause windows style newline to be inserted, and also mess around with some folders.
- Use unzip to extract the support libs outside the opensg source folder.
- If you cant make the batchfile for configure, execute each command individually on the cygwin console.
- Make sure to add --enable-glut to the configure line (I have intentionally left out jpeg, jasper, tiff etc)
./configure --with-compiler=cl.net2005 --prefix=BUILD --enable-win-localstorage --enable-png --with-png=/Project/supportlibs --with-glut=/Project/supportlibs --enable-glut
- On doing a make, you might come across a weird error about std:: not being defined in FlexLexer.h. Open this file, and remove std:: from front of FLEX_STD. Save and compile again.
- For CL.exe, you need to modify the makefile for compiling programs and tutorials
- add /link to begining of LDFLAGS
- remove -o $@ (something like that... and do not use /out also).
- add /link to begining of LDFLAGS
- Copy all dlls from support lib (that you extracted above) to Windows\system32. Do not overwrite the existing ones.
Compiling OpenSG with QT4 support
I am using a Linux box running XUbuntu, and came across several problems while compiling OpenSG with QT4 support. Here is what I did to get my source compiling. The changes mentioned here are according to the linux and windows config. Also, I have made this document *after* I got my system up and running, hence the line numbers stated here are approximate ones. Please use these steps as a guide, not as a tool to fix your problems blind-folded.
Note
Green - steps required for Windows users only
- Install Qt4.x SDK (I used Qt4.5)
- Compile Qt
- This is needed for windows as Qt comes with default lib files for g++ (*.a). You cannot link to these files using VS2005.
- Open the Visual Studio cmd prompt
- Use this cmdline: configure -shared -opensource -release -no-fast -stl -platform win32-msvc2005 -arch windows -no-webkit
- configure opensg with options for enabling Qt4 (these are in addition to the other options we have already used)
./configure --with-compiler=cl.net2005 --prefix=BUILD --enable-win-localstorage --enable-png --with-png=/Project/supportlibs --with-glut=/Project/supportlibs --enable-glut --enable-qt4 --with-qt4includedir=/cygdrive/c/Qt4/qt/include --with-qt4libdir=/cygdrive/c/Qt4/qt/lib --with-qt4bindir=/cygdrive/c/Qt4/qt/binAlso, do not condence the cmd line to --with-qt4dir="bla bla" as it is unable to pick up libraries for some reason.
- QT4.x has several chages to the organization of the include folder; hence we make some changes to accomodate them.
File = OpenSG/Builds/<arch>/CommonPackages/commonQT4.mk
- Add this line after defining INCLUDE_QT4
INCLUDE_EXTRA_QT4 := -I$(INCLUDE_QT4)/Qt -I$(INCLUDE_QT4)/QtGui -I$(INCLUDE_QT4)/QtOpenGL -I$(INCLUDE_QT4)/QtCore -I$(INCLUDE_QT4)/Qt3Support -I$(INCLUDE_QT4)/QtDesigner
- Add this to the Qt4 libs
LIB_QT4 := QtCore4.lib QtGui4.lib QtOpenGL4.lib Qt3Support4.lib QtNetwork4.lib
File = OpenSG/Common/DefaultRules.mk
- line 62 for Windows config - add $(INCLUDE_EXTRA_QT4) to the action line of the rule.
- line 75 or 76 for linux config - add $(INCLUDE_EXTRA_QT4) to the action line of the rule.
- line ~167 - locate "linux_make_depends" [line 146 for Wndows - win_make_depends] and add the INCLUDE_EXTRA_QT4 to the end of the cmdline.
- $(CC) $(DEPEND_OPTION) $< $(CCFLAGS) $(CCLOCALFLAGS) $(INCL) \
$(INC_OPTION)$(OBJDIR) $(INC_OPTION) $(INCLUDE_EXTRA_QT4)
- locate CONFIGURED_QT4 (line numbers in approx 395 to 399 / line 383-386 for Windows)
- Remove -i option from rule with %_qt.h and %_qt.cpp (not sure if this exists for %_qt.cpp)
- Add the INCLUDE_EXTRA_QT4 macro to moc cmdline for %_qt.cpp rule
$(MOC) $< -DOSG_WITH_QT -I$(INCLUDE_QT4)/QtDesigner $(INCLUDE_EXTRA_QT4) -o $@
File = common/common.i686-pc-cygwin-cl.net2005.mk (assuming you are using VS2005)
- Line 117: CompilerMajorVer = 14 (get rid of the script. It is giving wrong result. 14 comes from the version dumped when you run cl.exe on console.)
- Line 131: add -DOSG_COMPILEWINDOWATLIB /bigobj (-D stuff allows Qt files to be included as __dll_import; second one allows large obj files)
- Line 188/189: Path to your platform sdk include and lib. For me it is "C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK".
- Line 294: INCL_$(OS_BASE) := ...
Hard code -I"<path to platformsdk>\include" -LIBPATH:"<path to platformsdk>\lib" I found no better place to place these two. Do not use the AdditionalInclude and Lib varialbles a
few lines below; as they will cause make to start complaining about your makefiles.
- Please correct the path to your VS2005 include/lib folders if you are using a 64 bit os... the correct path has "Program Files (x86)".
- Compilation should go smoothly after these changes, and you will see another libOSGWindowQT4.so / libOSGWindowQT4.lib file generated in the lib folder.
- do a make install to copy the files to /usr/local/... or whatever folder you specified in the configure options.
- Also make sure that you copy the lib files to /usr/lib or some place which is in the loader serarch path; otherwise your app will fail to load.
- Also make sure that you have copied OpenSG/<arch>/bin/osg-config to your /usr/bin folder.
** -i option will ask the meta-object-compiler not to place any additional #includes in the generated _moc.cpp file. If this is allowed, then any Qt specific class usage will trigger an error of non-usage of QOBJECt and other similar namespace related errors. By removing the -i option we allow the moc to place the required #includes that indirectly include the necessary Qt files, solving our problems.
Building a Simple OpenSG based app in QT4.x
- Make a simple Qt app using the tutorial provided at http://www.opensg.org/doc-1.6.0/QT.html
- Go the the cmdline and navigate to the folder containing your project code.
- Type qmake (troubleshooting - *)
- Open the Makefile generated and add the following lines to the start of the file (use --opt instead of --dbg if using release version)
- OSGCONFIG=osg-config
OSG_CPPFLAGS=$(shell $(OSGCONFIG) --cflags --dbg Base System QT4)
OSG_LIBS=$(shell $(OSGCONFIG) --libs --dbg Base System QT4)
- OSGCONFIG=osg-config
- Add $(OSG_CPPFLAGS) to end of CXXFLAGS
- Add $(OSG_LIBS) to end of LIBS
- Save and close Makefile
- Go to main.cpp and make these changes (otherwise you will get a segmentation fault on Linux)
- #include "OpenSG/OSGQT4WindowBase.h"
- in main(), add this as the first line: OSG::osgInit(argc, argv); -- missing this line will cause the app to crash in the vicinity of a getAspect() function
- #include "OpenSG/OSGQT4WindowBase.h"
- Make the project by typing make
- Execute the project file :)
Troubleshooting
* If qmake is not found, use the full path to qmake. It is usually in the <QT4.x dir>/qt/bin
** Every time you use qmake, you will loose all changes to the makefile. So make sure that once you made your changes to makefile, avoide using qmake unnecessarily (and/or make a copy of the Makefile for easy cut/paste).
*** osg-config is usually placed in /usr/bin after a make install on OpenSG. If it wasn't copied for some reason, you can find it at OpenSG/Builds/<arch>/bin.
*** osg-config is usually placed in /usr/bin after a make install on OpenSG. If it wasn't copied for some reason, you can find it at OpenSG/Builds/<arch>/bin.
Creating OpenSG widgets in QT4
OpenSG provides a QT4 designer widget that we can use as our starting point. The OpenSG widget details File = OpenSG/OSGQGLManagedDesignerWidget_qt.h
Class = OSGQGLManagedDesignerWidget
We can start with subclassing this osg widget class; and add the functionality we need. Don't forget the Q_OBJECT macro if this widget need access to the signal-slot mechanism.
Well, that was simple enough, and really not worth mentioning. But the real reason for including this section is when we are using g++ (don't think that this is a problem with other compilers).
Once you have created the new widget class, and placed it in your Qt form/dialog; you will be hit by a compiler error which looks like
undefined reference to `vtable for <yourWidgetClass>'Well, that was simple enough, and really not worth mentioning. But the real reason for including this section is when we are using g++ (don't think that this is a problem with other compilers).
Once you have created the new widget class, and placed it in your Qt form/dialog; you will be hit by a compiler error which looks like
I googled for this error, and found that g++ spits it out if you have declared some virtual function in your subclass, but not defined it in your code.
Something like this
class A : public B
{
...
public:
virtual void foo(); // foo() declared
};
// foo() not defined
A second look at your code, and you might say that this is not the case with you; that you have don't have any virtual functions or have defined *all* the virtual functions. That may be true :) but the problem lies in the Q_OBJECT macro. It declared/overrides a couple of virtual functions, but doesn't define them. You can see for yourself by including the -E option in g++ [ g++ -E <more usual flags> yourWidget.cpp ].
I don't have an immediate solution to this problem, except that you take out the Q_OBJECT macro; but this will prevent your widget from recieving any signals / slot messages.
Update: I was blocked on this vtable error since yesterday; and did some experiments with test code. I found out that even if the virtual functions are distributed across several files, but are compiled and linked together, we should not get this error. I scanned thru the commandlines being executed, and found that one of my object file was missing. This was somehow being missed out by qmake. Once I added this file to the final object list, everything was fine.
I don't have an immediate solution to this problem, except that you take out the Q_OBJECT macro; but this will prevent your widget from recieving any signals / slot messages.
Update: I was blocked on this vtable error since yesterday; and did some experiments with test code. I found out that even if the virtual functions are distributed across several files, but are compiled and linked together, we should not get this error. I scanned thru the commandlines being executed, and found that one of my object file was missing. This was somehow being missed out by qmake. Once I added this file to the final object list, everything was fine.
No comments:
Post a Comment