使用armadillo和hdf5库的简单代码的C ++构建错误 [英] C++ building error for a simple code using armadillo and hdf5 libraries

查看:1334
本文介绍了使用armadillo和hdf5库的简单代码的C ++构建错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C ++和armadillo很新,我遇到了下面描述的建筑错误。我试图测试以下简单的代码将犰狳矩阵保存为hdf5文件:

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 »

编译指令如下: / p>

The compilation instruction is as follow:

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

我在linux Fedora 20系统上使用CodeBlocks。我有包装的HDF5-devel,可以在 / usr / include /
中找到hdf5.h我也使用 #define ARMA_USE_HDF5 在 config.hpp 。我使用最新版本的armadillo(4.450)和gcc 4.8.3。

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.

我错过了一个链接吗?对我来说,添加-larmadillo和-lhdf5(如在armadillo的用户指南中所述)应该就足够了。任何线索?
感谢

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

推荐答案

由于基于Linux系统上不同版本的HDF5库的各种问题,Armadillo已禁用HDF5库的自动检测。如果您想要使用HDF5与Armadillo,有两个选项:

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。
打开armadillo .tar.gz包,并编辑CMakeLists.txt文件。取消第231到238行的注释,从 find_package(HDF5)开始(即删除#个字符)。修改CMakeLists.txt后,请按照README.txt文件中所述运行基于cmake的安装。

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.

2。
通常(不修改CMakeLists.txt)安装Armadillo,然后使用(一行)编译程序:

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

奖励分数:
如果您安装了高速 OpenBLAS 媒体库,并且想要犰狳要使用它而不是标准BLAS,请将 -lblas 更改为 -lopenblas

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

这篇关于使用armadillo和hdf5库的简单代码的C ++构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆