Skip to content

Compiling DeepCV (C++)

Compilation of TensorFlow C++ API

TensorFlow C++ API used in this work was built from the source. One can follow step-by-step instructions to build the TensorFlow libraries using GCC 9.3.1 for C++ 14:

  1. Install Python 3.7 or a newer version and Bazel 3.7.2

  2. Install ProtoBuf 3.9.2 package with -D_GLIBCXX_USE_CXX11_ABI=0 flag for ABI compatibility

  3. Download the tarball from to a local machine

    tar -xzvf v2.7.4.tar.gz
    cd tensorflow-2.7.4/

  4. Compile TensorFlow framework

    bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
        --config=opt -c opt \
        // \
        // \
        // \

  5. Create a single TensorFlow directory for C++ linkage

    export LIB_TF="/usr/local/tensorflow/"
    sudo mkdir $LIB_TF
    sudo cp -r bazel-bin/tensorflow/include/ $LIB_TF
    sudo cp -r /home/rangsiman/protobuf-3.9.2/include/google/ $LIB_TF/include/
    sudo mkdir $LIB_TF/lib
    sudo cp -r bazel-bin/tensorflow/*.so* $LIB_TF/lib/
    sudo cp -r /home/rangsiman/protobuf-3.9.2/lib/*.so* $LIB_TF/lib/
    More details on package dependencies installation and compilation of TensorFlow C++ API are available at

Compilation of PLUMED with DeepCV and TensorFlow

DeepCV is implemented in PLUMED as a standalone module deepcv. The source code of a modified version of PLUMED is available at The following is instruction for compiling PLUMED with TensorFlow and DeepCV:

# Clone PLUMED2 DeepCV repository to local machine
git clone
cd plumed2-deepcv/

# Choose variable to directory to install PLUMED2, e.g.
export PREFIX="/home/rangsiman/plumed2-deepcv-install/"
# Set variable to TensorFlow directory for linkage, e.g.
export LIB_TF="/usr/local/tensorflow/"

# Configuring libraries
./configure --prefix=$PREFIX --enable-rpath \
    CPPFLAGS="-I${LIB_TF}/include/ -L${LIB_TF}/lib/" \
    LDFLAGS="-L${LIB_TF}/lib/ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath,$LIB_TF/lib/" \
    --disable-external-lapack --disable-external-blas \
    --disable-python --disable-libsearch --disable-static-patch \
    --disable-static-archive --enable-mpi --enable-cxx=14 \
    --disable-modules --enable-modules=adjmat+deepcv

# Compile and install in parallel using, e.g., 8 processors
make -j 8 CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14 -fPIC" 2>&1 | tee make.log
make -j 8 install 2>&1 | tee make_install.log

Note that the above procedure will compile PLUMED with MPI. Use --disable-mpi instead if you prefer serial compilation to parallel compilation.

Compilation of DeepCV C++ module

  1. Go to DeepCV directory:

    cd /path/to/plumed2/src/deepcv/

  2. The users can compile source code (deepcv.cpp) using either GCC compiler g++:

    # Set variable to TensorFlow directory for linkage, e.g.
    export LIB_TF=/usr/local/tensorflow/
    # compile
    g++ -Wall -fPIC -o deepcv.o deepcv.cpp \
        -O3 -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14 -fPIC \
        -I${LIB_TF}/include/ -L${LIB_TF}/lib \
        -ltensorflow -ltensorflow_cc -ltensorflow_framework
    or use Make (make):
    make CXXFLAGS="-std=c++14 -fPIC"
    Related header files are required to be in the same directory of source codes, else one needs to edit the absolute or relative path in Makefile.

  3. Then build a shared object file (

    g++ -shared -o deepcv.o