Primitives Library Integration

Integration of primitives library (pull request #912)

Fix build on Windows, Mac OS X and Linux