mirror hosted by tehsausage.com
PTypes: Compiling and Porting

C++ Portable Types Library (PTypes) Version 2.1


Top: Introduction: Compiling and Porting


Supported platforms and compilers

Windows: MSVC 6, VC.NET, Dev-C++/MinGW, BCC, Cygwin

FreeBSD: GNU C/C++

Linux/i386, Alpha, PPC, Sparc, AMD64: GNU C/C++

SunOS/Sparc: GNU C/C++

MacOS X/PPC (Darwin): CC - Apple Objective-C compiler

BSD/OS: GNU C/C++



The build process on all platforms produces 3 versions of the library: static single-threaded, static multithreaded and dynamic (shared) multithreaded. In addition, MSVC can build debug versions for each of these 3 libraries.

Single-threaded versions have a suffix 'n' (non-reentrant) in their names: libptypesn.a for UNIX and MinGW and ptypesn.lib for MSVC. They are somewhat faster and smaller than the multithreaded versions and are intended to be used in smaller projects that do not require to be linked with the slower reentrant system libraries.

The dynamic versions of the library have the library version number in their names: ptypes21.dll, libptypes.so.21 and libptypes.21.dylib. The version number in file names reflects incompatible changes and/or significant enhancement of functionality. Change in the third number in the version usually indicates a compatible improvement and/or bug fix release, so it is not reflected in the DLL/so file name.


Building on UNIX and MacOS X

In order to build the library on one of the UNIX systems listed above, run make in the library's root directory. The makefile in this directory actually calls makefiles in src/ and wshare/ with a suffix which is an output of uname on the given system (e.g. src/Makefile.Linux or src/Makefile.FreeBSD). Make builds the library and the demo program, and then places:

The public headers are in include/.

When building your own multithreaded application on Linux or FreeBSD, GCC requires you to specify a special command-line option -pthread which automatically links POSIX threads library and the reentrant version of libc. On Linux you should specify a macro -D_GNU_SOURCE in the command line to include the rwlock interface.

When building your multithreaded application on SunOS, you should specify a macro -D_REENTRANT and also link the following libraries: -lpthread -lposix4 for multithreaded applications, and in addition, -lsocket -lnsl for network applications. NOTE: if you omit -lpthread, the program links without errors, but then the thread objects fail to initialize.


Building on Windows with MSVC

The MSVC project files are:

A workspace file PTypes.dsw is provided for building all components and versions of the library.

You can include one of the project files in your own workspace. Make your project dependent of PTypes to automatically link the library to your program. To use PTypes headers you will have to explicitly specify the directory in your project settings, e.g. "..\ptypes\include".

In order to link a program to the DLL version of PTypes (ptypes21.dll) use PTYPES_DLL macro definition when compiling your modules. You may want to add a post-build command in the MSVC environment that copies the PTypes DLL to the directory where you build and debug your application.

You should link your application with the multithreaded version of CRTL, except when using the single-threaded ptypesn.lib. When compiling with the dynamic version of PTypes, it is recommended also to use the multithreaded DLL version of CRTL.

Specify an additional library ws2_32.lib if you are using PTypes' IP socket classes.


Building on Windows with Dev-C++/MinGW

The Dev-C++ projects files are in win32 directory and have an extension .dev.

win32/PTypes_Lib_ST.dev and win32/PTypes_Lib.dev build the static versions (single and multithreaded) of the library named libptypesn.a and libptypes.a and copy them to lib/. With Dev-C++/MinGW you can link the library to your application by specifying the option -lptypesn or -lptypes and providing the correct library path in Project Options dialog.

win32/PTypes_DLL.dev builds the multithreaded DLL version of the library named ptypes21g.dll and copies it to so/. Although an import library is built along with the shared object, with MinGW compiler tools you can directly link your program with the PTypes DLL.

win32/wshare.dev builds the demo program and places it in bin/wshare.exe.

These project files produce binaries without any debugging information and use directories Release_ST, Release and DLL_Release to place all intermediate binaries. If you need debug versions, create separate project files (or copy them from the existing ones), add proper compiler options for debugging/profiling and change the output directories to Debug_ST , Debug and DLL_Debug respectively.


Building on Windows with BCC

The makefile for Borland's C/C++ compiler (aka C++Builder) is src\ptypes.mak. You will need tasm32.exe since some modules contain assembly code which BCC compiles using an external assembler. The BCC makefile for wshare is wshare\wshare.mak. Currently BCC only builds the static multithreaded version of the library.


PTypes namespace

The entire PTypes interface is enclosed within a namespace called pt. The header file <pport.h> provides a macro USING_PTYPES, which is equivalent to using namespace pt. This macro allows you to use PTypes interface symbols without the scope specifier pt:: in your source code.


Porting the library to other platforms

The author would greatly appreciate any effort to port the library to other popular platforms. If you either ported the library or just found that PTypes builds with no problem under your favorite platform with your favorite compiler, then all you'd have to do is to create a makefile with proper definitions in it. Take a look at Makefile.FreeBSD or Makefile.SunOS, for example. Besides OS_CXXOPTS you can specify additional libraries through OS_LDLIBS. Name your makefile so that running make Makefile.`uname` would work on the given operating system. Try to build the library and then run src/ptypes_test to make sure the library is functioning properly.

And finally, if you send the changes to the author, then (obviously) others would be able to benefit from using PTypes on your favorite operating system with your favorite compiler.

See also: Deploying the shared (dynamic) library


PTypes home