Wednesday, April 27, 2011

How to compile STLport with Visual Studio 7 (.NET)



STLport is a fast, portable, free, multi-featured and opensource version of the standard library. In this tutorial I will demonstrate how to get it working under Visual Studio C++ 7 (.NET).

1. Download the windows version of STLport from www.stlport.org.

2. Unzip it into any directory go to the src directory and rename the file vc7.mak to makefile.

3. Go to your command prompt and change directory to the Visual C++ bin directory like this "cd Program Files\Microsoft Visual Studio .NET\Vc7\bin " this is where you find the vcvars32.bat file. Now enter in vcvars32.bat. Then change to the directory where you unzipped STLport.

4. Now enter "nmake clean all" and STLport will build itself as a release build. To get a debug build enter "nmake debug_static" and then "nmake debug_dynamic".

5. After building enter "nmake install" and it will install all necessary headers, libs and dlls into their appropriate directories.

6. Now open Visual Studio. Then go to the "Options" menu and find the "Projects" heading, click on that and go to the "VC++ directories" heading. There you select "Include Files" and you add the STLport header directory which should be "Program Files\Microsoft Visual Studio .NET\Vc7\include\stlport". Then click on the up arrow and make sure that the directory goes all the way to the top of the list.

7. To get STLport to run in debug mode for debug builds write the following preprocessor code before including any stl headers. Also you have to get rid of windows.h macros max and min because they interfere with numeric limits max and min functions. Here is how you can setup your headers.  

#ifdef NDEBUG 
# undef _STLP_DEBUG 
#else 
# define _STLP_DEBUG 1 
#endif 
#ifdef WIN32 
# undef max 
# undef min 
#endif 

//STL includes 
#include <limits> 
#include <vector> 
#include <map> 
#include <string> 
#include <set> 
#include <memory>  

//Stream includes  
#include <fstream> 
#include <iostream> 
#include <iomanip>  

namespace 
{ 
//C Library includes  
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h>  
} 

#include <assert.h>  

using namespace _STL;

8. If you want to use stream includes from STLport you have to get rid of Microsoft's std libs from the build. You do this by going to the property sheet for the project you are building and go to the headings "Linker" and then "Input" and use the ignore specific library feature and type "libcmt.lib" for Release builds and "libcmtd.lib" for Debug builds. Other useful self defining features of STLport are:  

//changes its namespace _STL into std 
#define _STLP_NO_OWN_NAMESPACE 
//with this define you don't need to rely on using namespace_STL; 
#define _STLP_NO_NAMESPACES 
#define _STLP_USE_SYSTEM_ASSERT 
//define this with MFC and include <stl/_config.h> then include <afx.h> instead of <windows.h> 
#define _STLP_USE_MFC  
//bounds checker needs this defined but makes your app run slower 
#define _STLP_USE_MALLOC  
//bounds checker needs this defined but makes your app run slower 
#define _STLP_USE_NEWALLOC  
//set this if you don't want multithreading 
#define _STLP_NO_THREADS 
#define _STLP_USE_STATIC_LIB 
#define _STLP_USE_DYNAMIC_LIB  
//debug for memory allocations 
#define _STLP_DEBUG_ALLOC  
//does not initialize allocated memory to zero like release builds 
#define _STLP_DEBUG_UNINITIALIZED  
//if you are having trouble building in debug mode try this 
#define _STLP_USE_ABBREVS

Written by: Paul

No comments:

Post a Comment