Top: Introduction: Compiling and Porting
Supported platforms and compilers
Linux/i386, Alpha, PPC, Sparc, AMD64: GNU C/C++
MacOS X/Intel, PPC: CC - Apple Objective-C compiler
SunOS/Sparc, i386: GNU C/C++
FreeBSD: GNU C/C++
HP-UX: aCC
Windows: MS Visual Studio 7, 8
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:
- Static single-threaded version -> lib/libptypesn.a
- Static multi-threaded version -> lib/libptypes.a
- Shared multi-threaded version -> so/libptypes.so.21 (libptypes.21.dylib on MacOS X)
- Demo program -> 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 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 7 or 8
The MSVC project files are:
- win32\PTypes_Lib_ST.vcproj - static single-threaded version
- win32\PTypes_Lib.vcproj - static multithreaded version
- win32\PTypes_DLL.vcproj - dynamic multithreaded version
- win32\wshare.vcproj - the demo program
A "solution" file PTypes.sln is provided for building all components and versions of the library.
You can include one of the project files in your own solutions. 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 against 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.
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