Compiling PhysBAM using clang 2015-01-05
The purpose of this post is to document the process I went through to compile the public PhysBAM library using clang. With clang support XCode should also compile the code properly.
Repository: https://github.com/hmazhar/physbam_public OS: OSX 10.10.1 Compiler: Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix
Most of the compilation errors were not unique and came up quite often. The most prevalent errors were related to the following.
- Missing functions - Usually defined after use, Fix is to move them before use or create prototypes at the top of the file
- Two Phase name lookup - This error manifests itself as the following:
error: call to function 'Foo' that is neither visible in the template definition nor found by argument-dependent lookup
The problem is caused by the function, in this case “Foo” being defined in the base class of the templated child class. There are two ways to fix this error, first as documented here is to add a this-> before any functions that are defined in the base class. The alternative is to explicitly scope the function with the child class. Both seem to work just fine, I thought that the first method, using this->, is a little bit cleaner.
Other errors exist but were not common, they will be covered here on a case by case basis.
In OSX 10.10 Yosemite the
header file contains code that can be processed by clang but not GCC. The specific error that GCC 4.9 (via homebrew) produces is:
/usr/include/dispatch/object.h:143:15: error: expected unqualified-id before '^' token typedef void (^dispatch_block_t)(void); ^ /usr/include/dispatch/object.h:143:15: error: expected ')' before '^' token /usr/include/dispatch/object.h:362:3: error: 'dispatch_block_t' has not been declared dispatch_block_t notification_block); ^
On OSX clang is one of the default compilers supported but the version of clang on OSX does not come with clang-format. There are two options for installing:
See related homebrew pull request here
brew tap tcr/tcr brew install clang-format
With this option you can copy clang-format to your /usr/local/bin directory (or a location located in your path)
Download clang binaries link
Extract and copy clang-format
Compression of Simulation Data using ZLib 2014-11-06
This post will cover a simple way to compress simulation data in memory using ZLib. The goal is to write out compressed data directly without having to deal with binary data formats.
I do a lot of rendering with PovRay which means that I need to store comma separated ascii files because that is the only data format supported. The problem is that when I’m saving data for millions of objects the files can become several hundred MB in size.
I propose one solution where all simulation data is stored compressed and a simple program can be used to decompress it and write it out as povray compatible files when needed.
My data is stored in a std::stringstream which I normally stream out to a file. I would like to directly compress this stream and when I need the data, decompress it back into a string.