More than 1 year has passed since last update.

準備

パッケージインストール
sudo port install python27 py27-scipy py27-numpy py27-networkx py27-h5py py27-matplotlib py27-nose nosetests_select
sudo port install boost +python27
sudo port install doxygen graphviz py27-pygraphviz
gitでクローン
git clone https://github.com/opengm/opengm.git
cd opengm/
mkdir build
cd build
cmake ..

ビルド

外部ライブラリの追加
make -k externalLibs

エラーが出て止まっても泣かない...
コンパイルできた外部ライブラリだけは,../CMakeFileに追加する.

  • 以下では外部ライブラリとしてAD3, TRWS, MRF, QPBO, MAXFLOW, PLANARITY, BLOSSOM5を追加,
  • その他にboostとhdf5を利用.
  • pythonバインドも作成(PLANARITY, BLOSSOM5を追加しておかないとダメ,というバグあり(2015/11/27)).
../CMakeFileの修正(例).外部ライブラリの追加,Boostなど.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d5fb1a9..d58c167 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,30 +67,30 @@ endif()
 OPTION(BUILD_EXAMPLES "Build Examples" ON)
 OPTION(BUILD_TUTORIALS "Build Tutorials" ON)
 OPTION(BUILD_COMMANDLINE "Build Commandline" OFF)
-OPTION(WITH_AD3 "Include AD3" OFF)
+OPTION(WITH_AD3 "Include AD3" ON)
 OPTION(WITH_CPLEX "Include CPLEX" OFF)
 OPTION(WITH_GUROBI "Include GUROBI" OFF)
-OPTION(WITH_BOOST "Include BOOST" OFF)
-OPTION(WITH_HDF5 "Include HDF5" OFF)
-OPTION(WITH_TRWS "Include wrapper for TRWS code" OFF)
+OPTION(WITH_BOOST "Include BOOST" ON)
+OPTION(WITH_HDF5 "Include HDF5" ON)
+OPTION(WITH_TRWS "Include wrapper for TRWS code" ON)
 OPTION(WITH_GCO "Include wrapper for GCO code" OFF)
-OPTION(WITH_MRF "Include wrapper for MRF code" OFF)
-OPTION(WITH_QPBO "Include wrapper for QPBO code" OFF)
+OPTION(WITH_MRF "Include wrapper for MRF code" ON)
+OPTION(WITH_QPBO "Include wrapper for QPBO code" ON)
 OPTION(WITH_FASTPD "Include wrapper for FastPD code" OFF)
-OPTION(WITH_MAXFLOW "Include wrapper for MAXFLOW code" OFF)
+OPTION(WITH_MAXFLOW "Include wrapper for MAXFLOW code" ON)
 OPTION(WITH_MAXFLOW_IBFS "Include wrapper for MAXFLOW-IBFScode" OFF)
 OPTION(WITH_LIBDAI "Include wrapper for LIBDAI code" OFF)
 OPTION(WITH_DAOOPT "Include wrapper for DAOOPT code" OFF)
 OPTION(WITH_MPLP "Include wrapper for MPLP code" OFF)
 OPTION(WITH_SRMP "Include wrapper for SRMP code" OFF)
-OPTION(WITH_PLANARITY "Include wrapper for PLANARITY code" OFF)
-OPTION(WITH_BLOSSOM5 "Include wrapper for BLOSSOM5 code" OFF)
+OPTION(WITH_PLANARITY "Include wrapper for PLANARITY code" ON)
+OPTION(WITH_BLOSSOM5 "Include wrapper for BLOSSOM5 code" ON)
 OPTION(WITH_OPENMP "Include OpenMP" OFF)
 OPTION(WITH_VIGRA "Include VIGRA" OFF)
 OPTION(WITH_CONICBUNDLE "Include ConicBundleLibrary" OFF)
 OPTION(WITH_MATLAB "Activate MatLab-Code" OFF)
 OPTION(BUILD_CONVERTER "Build several converters" OFF)
-OPTION(BUILD_PYTHON_WRAPPER "Build python wrapper" OFF)
+OPTION(BUILD_PYTHON_WRAPPER "Build python wrapper" ON)
 OPTION(BUILD_MATLAB_WRAPPER "Build matlab wrapper" OFF)
 ###Grante needs C++11. Since we have not tested OpenGM under this standard yet, using Grante is realy experimental!!!
 ###OPTION(WITH_GRANTE "Include wrapper for grante" OFF)

以下ではシステムの/usr/bin/pythonを見に行かないようにcmakeのオプションを設定(macportsのpython2.7を利用).

再度CMake
rm CMakeCache.txt
cmake ..  \
  -DPYTHON_EXECUTABLE:FILEPATH=/opt/local/bin/python2.7 \
  -DPYTHON_INCLUDE_DIR:PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Headers/ \
  -DPYTHON_LIBRARY:FILEPATH=/opt/local/lib/libpython2.7.dylib 
そしてビルド
make -j 4
ドキュメント作成
make doc

テスト

そしてテスト
make test

Running tests...
...
100% tests passed, 0 tests failed out of 60

Total Test time (real) =  45.89 sec
pythonバインドをテスト
make test-python-wrapper

...
Ran 70 tests in 3.584s

OK
[100%] Built target test-python-wrapper

もしmake test-python-wrappernosetestsがないと言われたら

nosetestsをnosetests-2.7へリンク
sudo port select --set nosetests nosetests27

インストール

ローカルにインストールするなら
make DESTDIR=$HOME/local install

mkdir $HOME/local/usr/local/lib
cp ../build/src/external/libexternal-library-* $HOME/local/usr/local/lib

これで

  • $HOME/local/usr/local/include/opengm/以下にヘッダファイルが
  • $HOME/local/usr/local/lib/以下に外部ライブラリ用ライブラリが
  • $HOME/local/usr/local/lib/python2.7/site-packages/以下にpython用ライブラリが インストールされる.

ちなみに,外部ライブラリやpythonを使わないなら,OpenGMはヘッダファイルのみ.

設定:pythonバインドを使う

~/.bash_profileに追加
# opengm                                                                                                                                       
export LD_LIBRARY_PATH=$HOME/local/usr/local/lib/:$LD_LIBRARY_PATH
export PYTHONPATH=$HOME/local/usr/local/lib/python2.7/site-packages/:$PYTHONPATH

こうしてから

macportsのpython2.7を実行
$ python2.7
Python 2.7.10 (default, Oct 18 2015, 09:28:19) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import opengm
>>> 
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.