Menu

Developer documentation

RomanH

CalcPi Developer information

Building CalcPi is not a trivial task. It helps if you already have some knowledge of C/C++ and CMake.

CalcPi requires the following libraries and tools:

If no version is given in the list above, it does not matter and older versions can be used.

This Wiki page describes mainly the compilation of CalcPi. Some rudimentary information on compiling the third-party libraries is given.

Windows - Microsoft Visual C++

Download and install CMake, the download all libraries and extract them to individual directories. Compilation of boost is done from the command line (Start menu -> Microsoft Visual Studio 20xx -> Visual Studio Tools -> Visual Studio command prompt), while wxWidgets, MPIR and MPFR are compiled from within Visual Studio.
See the documentation of the respective libraries on how to compile them. I used the following command line for compiling boost:

.\b2 --build-dir=some_directory\boost_build toolset=msvc-10.0 --build-type=complete --stagedir=lib/win32 -j4 stage

and 64 bits:

.\b2 --build-dir=F:\Projects\boost_build toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 --stagedir=lib/win64 -j4 stage

For compiling MPFR with Visual Studio, you need a project file, download from here.

After all libraries have been built successfully, create a new folder called calc_pi and extract the source into a directory "src". Then create a batch file in calc_pi similar to this one:

SET PATH=%PATH%;path_to_cmake\bin

CALL "path_to_visual_studio\VC\vcvarsall.bat" x64

SET BOOST_ROOT=path_to_boost
SET BOOST_LIBRARYDIR=%BOOST_ROOT%/lib/win64/lib
SET Boost_ADDITIONAL_VERSIONS="1.53.0"

mkdir build_x64
cd build_x64
cmake -G "Visual Studio 10 Win64" -DCMAKE_CONFIGURATION_TYPES=Release;RelWithDebInfo;Debug -DMPIR_PATH="path_to_mpir/lib/x64/Release" -DMPFR_PATH="path_to_mpfr/lib/x64/Release" -DwxWidgets_ROOT_DIR="path_to_wxWidgets-2.9.4" -DEIGEN3_INCLUDE_DIR="path_to_eigen" ..\src

cd ..

Adjust the paths as needed. Then execute the batch file. If everything went smoothly, you now have a directory build_x64 with a Visual Studio solution file. Open it, compile, done!
It is also possible to use CMake-GUI, but I haven't tried that.

Windows - MinGW64

There are many ways how to use the MinGW64 compiler. I am using the TDM distribution, found here, along with MSYS, see installation description here.
Boost compilation:

b2.exe --build-dir=some_dir/boost_build toolset=gcc variant=debug,release link=static runtime-link=static --stagedir=lib/win64gcc --without-mpi -j4 stage
b2.exe --build-dir=some_dir/boost_build toolset=gcc variant=debug,release link=shared runtime-link=shared --stagedir=lib/win64gcc --without-mpi -j4 stage

b2.exe --build-dir=some_dir/boost_build toolset=gcc variant=debug,release link=static runtime-link=static architecture=x86 address-model=32 --stagedir=lib/win32gcc --without-mpi -j4 stage
b2.exe --build-dir=some_dir/boost_build toolset=gcc variant=debug,release link=shared runtime-link=shared architecture=x86 address-model=32 --stagedir=lib/win32gcc --without-mpi -j4 stage

For the compilation of MPIR, MPFR and wxWidgets I recommend a separate build directory. Commands for compiling MPIR:

cd path_to_mpir
mkdir build_mingw64tdm
cd build_mingw64tdm
mkdir install
../configure ABI=64 --build=core2-w64-mingw32 --enable-static --disable-shared --enable-cxx --enable-gmpcompat --prefix=path_to_mpir/build_mingw64tdm/install
make -j4
make install

If you prefer a "native" build (optimized to your PC), omit --build=...

Compiling MPFR is very similar:

cd path_to_mpfr
mkdir build_mingw64tdm
cd build_mingw64tdm
mkdir install
../configure --enable-thread-safe --with-gmp=path_to_mpir/build_mingw64tdm/install --prefix path_to_mpfr/build_mingw64tdm/install
make -j4
make install

Commands for compiling wxWidgets:

cd path_to_wxwidgets
mkdir build_mingw64tdm
cd build_mingw64tdm
../configure --disable-debug --disable-shared --disable-compat28 --with-opengl
make -j4

Finally, create a batch file similar to the one for Visual Studio.

SET PATH=%PATH%;path_to_cmake\bin;path_to_mingw64\bin

SET BOOST_ROOT=path_to_boost
SET BOOST_LIBRARYDIR=path_to_boost/lib/win64gcc/lib
SET Boost_ADDITIONAL_VERSIONS="1.53.0"

MKDIR build_mingw64tdm
cd build_mingw64tdm

REM Run cmake twice to override the found wxWidgets library directory (the first one is the wrong one)
cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="Release" -DMPIR_PATH="path_to_mpir/build_mingw64tdm/install" -DMPFR_PATH="path_to_mpfr/build_mingw64tdm/install" -DIS_64BITS=1 -DwxWidgets_ROOT_DIR="path_to_wxWidgets-2.9.4" -DEIGEN3_INCLUDE_DIR="path_to_eigen-3.1.3" ..\src
cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="Release" -DMPIR_PATH="path_to_mpir/build_mingw64tdm/install" -DMPFR_PATH="path_to_mpfr/build_mingw64tdm/install" -DIS_64BITS=1 -DwxWidgets_ROOT_DIR="path_to_wxWidgets-2.9.4" -DEIGEN3_INCLUDE_DIR="path_to_eigen-3.1.3" ..\src

path_to_mingw32\bin\mingw32-make.exe -j4
cd ..

Mingw-make seems to be missing from Mingw64, so I used the one from a Mingw32 installation. A bit strange, but it seems to work fine.

OS X

Since I'm not a OS X expert, and I don't even own a Mac, there may be better ways to do this than the ones I've found.

Compilation of MPIR (I omitted here the cd/mkdir/cd build_dir/make, find it above):

../configure --build=core2-apple-darwin11.1.0 --enable-static --disable-shared --enable-cxx --enable-gmpcompat --prefix=path_to_mpir/build_rel64/install

MPFR:

../configure --disable-thread-safe --with-gmp=path_to_mpir/build_rel64/install --prefix=path_to_mpfr/build_rel64/install

Compilation of wxWidgets (important: download the .tar.bz2 version, the zip version has Windows line endings which will fail!):

../configure --with-macosx-version-min=10.5 --with-opengl --enable-unicode --disable-shared --disable-compat28 --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --with-osx_cocoa
make -j4

The batch file for building CalcPi looks similar to this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
#

export BOOST_ROOT=path_to_boost_1_53_0
export BOOST_LIBRARYDIR=path_to_boost_1_53_0/stage/lib
export BOOST_LIBRARYDIR="1.53.0"

export MPIR_PATH=path_to_mpir-2.6.0/build_rel64/install
export MPFR_PATH=path_to_mpfr-3.1.2/build_rel64/install
export wxWidgets_ROOT_DIR=path_to_wxWidgets-2.9.4
export wxWidgets_LIB_DIR=path_to_wxWidgets-2.9.4/build_release64/lib
export wxWidgets_CONFIG_EXECUTABLE=$wxWidgets_ROOT_DIR/build_release64/wx-config
export EIGEN3_INCLUDE_DIR=path_to_eigen-3.1.3

mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE="Release" -DIS_64BITS=1 -DBOOST_ROOT=$BOOST_ROOT -DBOOST_LIBRARYDIR=$BOOST_LIBRARYDIR -DBOOST_LIBRARYDIR=$BOOST_LIBRARYDIR -DMPIR_PATH=$MPIR_PATH -DMPFR_PATH=$MPFR_PATH -DwxWidgets_ROOT_DIR=$wxWidgets_ROOT_DIR -DwxWidgets_LIB_DIR=$wxWidgets_LIB_DIR -DwxWidgets_CONFIG_EXECUTABLE=$wxWidgets_CONFIG_EXECUTABLE -DCP_USE_STATIC_LIBGCC=1 -DEIGEN3_INCLUDE_DIR=$EIGEN3_INCLUDE_DIR ../src
make

Linux

In most Linux distributions, GMP, MPFR and CMake are in the package repository, so you can do something similar to:

apt-get install gmp mpfr cmake

We need the newest versions of wxWidgets and boost, so we can't use package versions of those libraries.

Boost compilation is straight-forward, and wxWidgets compilation is similar to OS X:

../configure --with-opengl --enable-unicode --disable-shared --disable-compat28

The build script is the same as for OS X, except that the paths to MPIR and MPFR do not have to be set.

CMakeLists.txt parameters

The following parameters can be given to CMakeLists.txt (additionally to the library paths described above):

  • CP_DISABLE_OPENMP: Some compilers have a defective OpenMP implementation (I had crashes with MinGW32 in OpenMP code, for example). With this flag set (add -DCP_DISABLE_OPENMP=1 to the cmake command line) OpenMP is disabled even though the compiler would support OpenMP.
  • CP_USE_STATIC_LIBGCC: Some GCC distributions on Windows link the C and C++ libraries dynamically (shared). With this flag, they are linked statically, by adding the link flags "-static-libgcc -static-libstdc++".

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.