Last Updated: Jun 8, 2012, broken links to “Related Resources” are now fixed. Thanks to Jens Mertelmeyer, this problem is found and fixed in time. Thank you.

If this page helped you in any online or printed publication, please don’t forget to mention it, and help me spread it to more people in need. Thank you very much.

QSlim is a light-weight software developed by M. Garland, which can simplify mesh models swiftly, maximally preserving their geodesic properties. It is very important for model retrieval and other applications that require small data scale as well as relatively accurate geodesic properties to overcome the difficulties of non-rigid transform.

Lately I’ve been working on my undergraduate thesis, which, must use the QSlim software. However, I found a problem (which I may probably write a blog about later) with the DLL version as well as the author’s compilation of QSlim 2.0, so I decided to download the source for QSlim 2.1 and compile it on my own computer. After failed by Cygwin, I turned to the native Visual Studio on my Windows Machine.

For related resources (compiled EXE file, VS2010 solution and configured libraries), please skip to Related Resources.

Environment

CPU Architecturex86
Operating SystemWindows 7 Ultimate SP1
Visual Studio2010 Pro

Source code is directly downloaded from Garland’s page. If you are using other systems or IDE’s, you may also find the libs required by QSlim in this article useful.

Luckily enough, the author maintained a VC 6 workspace file(.dsw): “qslim-2.1/win32/SlimKit.dsw”. Open it and Visual Studio will automatically convert the version for you if you are using VS 2005 or above. The author has already included plentiful resource in each project’s “External Dependencies”.

So is that enough? Can we proceed and build the project QSlim easily and happily? Sadly, no. It envolves many referred libraries and cross-platform issues, which I will analyze below. Due to the solution’s build order: MixKit libgfx QSlim QVis SMFView, I’ll introduce in order how I compiled MixKit, libgfx, and QSlim in order below. As for the two projects that’s left, I’m sure you’ll be able to compile them with the tricks in this article.

1. MixKit

1.1

Try building the project directly and you will receive this compiler error. (In all error info below I’ll hide my local path of QSlim as “qslim-2.1")

1>  MxStdGUI.cxx 
1>qslim-2.1\libgfx\include\gfx/gui.h(22): fatal error C1083: Cannot open include file: 'FL/Fl.H': No such file or directory

This problem is relatively easy. Download the required library fltk and unzip it somewhere (I used fltk 1.3.0 and unzipped it to “qslim-2.1\tools"). Then right click on the MixKit project, select “Properties”, choose from the left list “Configuration Properties > VC++ Directories”. Add to “Include Directories”: “..\tools\fltk-1.3.0;” (without the quotation marks but WITH the semicolon. If you are adding this path to the end of the original string, make sure you put a semicolon before this path).

What you just did tells the compiler where to find the missing header files. If you would like to add this library for all programs, then you’ll have to unzip it into your Visual Studio include path. Google for it as I won’t elaborate that here.

NOTE

  1. You should remember this “adding to include path” operation as it’s very useful in the rest part of this article as well as your future work with Visual Studio C++
  2. This relative path is relative to the directory where your project (.vcxproj) file is stored, *NOT* the source file, *NOR* the header file.
  3. In all configurations I use relative paths so that the solution is compilable even the directory’s been changed. You may use absolute ones if you want.

1.2

However, new problems comes.

1>  getopt.c
1>c1 : fatal error C1083: Cannot open source file: 'src\getopt.c': No such file or directory
1>  getopt1.c
1>c1 : fatal error C1083: Cannot open source file: 'src\getopt1.c': No such file or directory

This is caused by a directory in the project — “GNU getopt”. getopt is a useful command-line API in Unix-like operating systems, however it’s not supported by Windows/Visual Studio. Luckily, this directory seems not required by this library actually, so removing it will do the trick.

Now you have the MixKit library successfully compiled.

2. libgfx

2.1

The libgfx project compiles with a lot of warning messages and the following errors (I selected only the compiler information that’s related to errors):

1>  arcball.cxx
1>..\..\src\arcball.cxx(182): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
1>  baseball.cxx
1>..\..\src\baseball.cxx(53): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

This is due to a std library problem. Simply add to qslim-2.1/libgfx/include/gfx/gl.h: #include <string> will save a lot of .cxx files that are including this header.

Visual Studio also provides an easier approach to finding this file: double click the error message and you’ll open “arcball.cxx”; then right click on #include <gfx/gl.h> , select “Open Document <gfx/gl.h> Ctrl+Shift+G”.

2.2

The next error is familiar:

1>  gui.cxx
1>qslim-2.1\libgfx\include\gfx/gui.h(22): fatal error C1083: Cannot open include file: 'FL/Fl.H': No such file or directory

Remember 1.1? Now you’ll have to add to the include paths of “libgfx”: “..\..\..\tools\fltk-1.3.0;”. Note again that this path is relative to your project file.

2.3

Here comes an annoying part:

1>  raster-jpeg.cxx
1>..\..\src\raster-jpeg.cxx(22): fatal error C1083: Cannot open include file: 'jpeglib.h': No such file or directory
1>  raster-png.cxx
1>..\..\src\raster-png.cxx(18): fatal error C1083: Cannot open include file: 'png.h': No such file or directory
1>  raster-tiff.cxx
1>..\..\src\raster-tiff.cxx(14): fatal error C1083: Cannot open include file: 'tiffio.h': No such file or directory

These are due to that libgfx used some open source libraries to fulfill image-related tasks (JPEG, PNG, and TIFF). If you do not want to use these functions, comment out the code in the #ifdef, the precompiling directives, leaving only the part between #else and #endif. This won’t have negative effect on the following steps. Take raster-jpeg.cxx as an example, after commenting out unnecessary code, it should look like

/************************************************************************

  JPEG image file format support.
...
 ************************************************************************/

#include <gfx/gfx.h>
#include <gfx/raster.h>

// Quality factors are expressed on a 0--100 scale
int jpeg_output_quality = 100;

/* #ifdef HAVE_LIBJPEG

#include <stdio.h>
...
    return img;
}

#else */

bool write_jpeg_image(const char *, const ByteRaster&) { return false; }
ByteRaster *read_jpeg_image(const char *) { return NULL; }

//#endif

And you won’t encounter the following problems in this section. Please skip to QSlim. Or else, you’ll have to get the library files from

Header fileWhere you can get it
jpeglib.hhttp://www.ijg.org/
png.hhttp://www.libpng.org/
tiffio.hhttp://www.libtiff.org/

When these libraries are ready in your directory, set the include paths accordingly. If you are in a hurry, use the 1.4.x version of libpng, and skip to 2.4 when indicated. However, adding to include won’t solve the problem for good. You should get the following errors in the next compilation:

1>  raster-jpeg.cxx
1>qslim-2.1\tools\jpeg-8d\jpeglib.h(25): fatal error C1083: Cannot open include file: 'jconfig.h': No such file or directory
1>  raster-png.cxx
1>qslim-2.1\tools\lpng1510\png.h(434): fatal error C1083: Cannot open include file: 'pnglibconf.h': No such file or directory
1>  raster-tiff.cxx
1>qslim-2.1\tools\tiff-4.0.1\libtiff\tiff.h(30): fatal error C1083: Cannot open include file: 'tiffconf.h': No such file or directory

Succinctly speaking, you’ll need to rename some configuration header files. Please find in the root directory of each library and do the following

Rename from…To…
jconfig.vcjconfig.h
tiffconf.vc.htiffconf.h
scripts\pnglibconf.h.prebuiltpnglibconf.h

If you have questions regarding the third renaming, refer to http://www.libpng.org/pub/png/libpng-manual.txt and the file “scripts\makefile.vcwin32” under the library directory.

If you used libpng 1.4.x, you should not have found the pnglibconf file, which is ok, and should be able to skip to 2.4 now. Or else, if unfortunately you are using the 1.5.x of that library, you should get these errors

1>..\..\src\raster-png.cxx(42): error C2027: use of undefined type 'png_struct_def'
1>          qslim-2.1\tools\lpng1510\png.h(849) : see declaration of 'png_struct_def'
1>..\..\src\raster-png.cxx(42): error C2227: left of '->jmpbuf' must point to class/struct/union/generic type
1>..\..\src\raster-png.cxx(132): error C2027: use of undefined type 'png_struct_def'
1>          qslim-2.1\tools\lpng1510\png.h(849) : see declaration of 'png_struct_def'
1>..\..\src\raster-png.cxx(132): error C2227: left of '->jmpbuf' must point to class/struct/union/generic type

According to http://www.cegui.org.uk/phpBB2/viewtopic.php?f=2&t=5848 this is due to the upgrade of the library. I downloaded libpng 1.4.11 and it worked immediately — at least for now.

2.4

Now welcome to the last error in this project.

1>  raster-png.cxx
1>qslim-2.1\tools\lpng1411\png.h(421): fatal error C1083: Cannot open include file: 'zlib.h': No such file or directory

This is due to the missing zlib in your include directory. Download one and add it to your include path. Mine is: ..\..\..\tools\zlib-1.2.6;

Now libgfx is also ready.

3. QSlim

3.1

Try building QSlim, and you’ll get this:

1>  cmdline.cxx
1>..\..\tools\qslim\cmdline.cxx(17): fatal error C1083: Cannot open include file: 'getopt.h': No such file or directory

Remember when we were compiling MixKit we omitted a directory? This is it. This time there’s no escape, you’ll have to use a windows counterpart. Fortunately, there is one. XGetOpt is the solution you’ll need. Download it and add it to the include directory.

Also remember to add the “XGetopt.cpp” file in your project to avoid link problems.

NOTE In fact, we should have built the getopt function inside MixKit, so that when linking, it can be linked as binary. I did not find out until I finished compiling QSlim. What a shame.

3.2

The next problem is weird.

1>  cmdline.cxx
1>qslim-2.1\tools\XGetopt_demo\XGetopt.h(19): error C2143: syntax error : missing ';' before '*'
1>qslim-2.1\tools\XGetopt_demo\XGetopt.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>qslim-2.1\tools\XGetopt_demo\XGetopt.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>qslim-2.1\tools\XGetopt_demo\XGetopt.h(21): error C2061: syntax error : identifier 'TCHAR'

What I recommend is that you #include <tchar.h> in XGetopt.h, and switch in XGetopt.cpp from "stdafx.h" to <windows.h>, <stdio.h>, and <tchar.h>, as we are not using pre-compiled headers here.

3.3

The next problem is weirder.

1>..\..\tools\qslim\qslim.cxx(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

function main has no returning data type! Whatever, int will do the trick.

3.4

Now welcome to the final nasty part. In the following error message I omitted 20 lines of link errors

1>.\Release\QSlim.exe : fatal error LNK1120: 20 unresolved externals

Remember the include directory window? This time choose from the left “Configuration Properties > Linker > Input”, and add these two paths into your “Additional Dependencies”: ”../../libgfx/vc6/libgfx/Release/libgfx.lib;../../mixkit/Release/MixKit.lib;”

This is to tell your linker where the external binary resources are located, so that external libraries can be linked in to complete your QSlim.exe.


Now you should be able to successfully compile your QSlim 2.1 with Visual Studio. Enjoy!!

Related Resources

The compiled QSlim.exe (Configuration:”Release”, Platform:”Win32”): QSlim.zip

The full configured VS2010 solution with all required libraries packed: qslim-2.1.zip

See Also…

An Unofficial “Bugfix” for QSlim 2.1