C++ Portable Types Library (PTypes) Version 1.7

Top: Introduction: Compiling and Porting

Supported platforms and compilers

Windows: MSVC, BCC


Linux/i386, Alpha, PPC, Sparc: GCC

SunOS/Sparc: GCC

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

Building on Unix

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 will build the library and the demo program, and will then copy the static version of the library as lib/libptypes.a, the shared object version as so/ (so/libptypes.dylib on MacOS) and the demo program as bin/wshare.

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 will automatically link POSIX threads library and the multithreaded 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.

There is a known problem on Linux with GCC 2.96: multithreaded applications may crash when running many threads and intensively using dynamic memory allocation. It is recommended to compile such projects with GCC 2.95.

Building on Windows (MSVC or BCC)

MSVC: The MSVC project files are named win32\PTypes_Lib.dsp and win32\PTypes_DLL.dsp for the static and the dynamic versions of the library respectively. You can include one of these project files in your workspace. Make your project dependent of PTypes - this will 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 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 own application, since otherwise your program won't be able to find the DLL module.

You should link your application with the multithreaded version of CRTL. When compiling with the dynamic version of PTypes, it is recommended also to use the DLL version of CRTL.

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

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.

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. See, for example, src/ptypes_test.cxx.

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 CXXOPTS you can specify additional libraries through 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