C++ building error for a simple code using armadillo and hdf5 libraries

被刻印的时光 ゝ 提交于 2019-12-19 10:38:08

问题


I'm quite new to C++ and armadillo, and I get stuck with a building error describe below. I'm trying to test the following simple code to save an armadillo matrix as hdf5 file:

#include <iostream>
#include <armadillo>

using namespace std;
using namespace arma;

int main()
{
    mat A = randu<mat>(240,320);
    A.save("A.hdf5",hdf5_binary);

    return 0;
}

When compiling, I get the following errors:

/usr/include/armadillo_bits/hdf5_misc.hpp:131: undefined reference in « arma_H5T_NATIVE_DOUBLE »
/usr/include/armadillo_bits/hdf5_misc.hpp:131: undefined reference in « arma_H5Tcopy »
obj/Debug/main.o: in function « bool arma::diskio::save_hdf5_binary<double>   (arma::Mat<double> const&, std::string const&) »:
/usr/include/armadillo_bits/diskio_meat.hpp:1299: undefined reference in « arma_H5Eset_auto »
/usr/include/armadillo_bits/diskio_meat.hpp:1308: undefined reference in « arma::H5check_version(unsigned int, unsigned int, unsigned int) »
/usr/include/armadillo_bits/diskio_meat.hpp:1308: undefined reference in « arma_H5Fcreate »
/usr/include/armadillo_bits/diskio_meat.hpp:1315: undefined reference in « arma_H5Screate_simple »
/usr/include/armadillo_bits/diskio_meat.hpp:1324: undefined reference in « arma_H5Dcreate »
/usr/include/armadillo_bits/diskio_meat.hpp:1330: undefined reference in « arma_H5Dwrite »
/usr/include/armadillo_bits/diskio_meat.hpp:1333: undefined reference in « arma_H5Dclose »
/usr/include/armadillo_bits/diskio_meat.hpp:1334: undefined reference in « arma_H5Tclose »
/usr/include/armadillo_bits/diskio_meat.hpp:1335: undefined reference in « arma_H5Sclose »
/usr/include/armadillo_bits/diskio_meat.hpp:1336: undefined reference in « arma_H5Fclose »

The compilation instruction is as follow:

g++ -Wall -fexceptions -O2 -g -larmadillo -lhdf5 -c main.cpp -o main

I'm working with CodeBlocks on a linux Fedora 20 system. I have the packaged HDF5-devel and could find the hdf5.h in /usr/include/ I also activated hdf5 in armadillo using the #define ARMA_USE_HDF5 in config.hpp. I use the latest version of armadillo (4.450) and gcc 4.8.3.

Did I missed a link ? To me, adding -larmadillo and -lhdf5 (as said in armadillo's users guide) should be enough. Any clue ? Thanks


回答1:


Due to various issues with differing versions of HDF5 libraries on Linux-based systems, the authors of Armadillo have disabled automatic detection of the HDF5 library. If you want to use HDF5 with Armadillo, there are two options:

1. Unpack the armadillo .tar.gz package, and edit the CMakeLists.txt file. Uncomment lines 231 to 238, starting with find_package(HDF5) (ie. remove the # characters). Once you have modified CMakeLists.txt, run the cmake based installation as described in the README.txt file.

OR

2. Install Armadillo normally (without modifying CMakeLists.txt), and then compile your programs using (all on one line):

g++ main.cpp -o main -O2 -DARMA_DONT_USE_WRAPPER -DARMA_USE_BLAS -DARMA_USE_LAPACK -DARMA_USE_HDF5 -lblas -llapack -lhdf5

Bonus points: if you have the high-speed OpenBLAS library installed and want Armadillo to use it instead of standard BLAS, change -lblas to -lopenblas



来源:https://stackoverflow.com/questions/26295725/c-building-error-for-a-simple-code-using-armadillo-and-hdf5-libraries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!