我對C++和犰狳很陌生,並且遇到下面描述的構建錯誤。我想測試以下簡單的代碼保存一個犰狳矩陣HDF5文件:使用犰狳和hdf5庫的簡單代碼的C++構建錯誤
#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;
}
編譯時,我得到以下錯誤:
/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 »
彙編指令如下:
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
中激活了犰狳中的hdf5。我使用最新版本的犰狳(4.450)和gcc 4.8.3。
我錯過了一個鏈接?對我而言,添加-larmadillo和-lhdf5(如在犰狳的用戶指南中所述)應該足夠了。任何線索? 謝謝
可能有[g ++鏈接順序依賴關係nking c代碼到c + +代碼](http://stackoverflow.com/questions/3363398/g-linking-order-dependency-when-linking-c-code-to-c-code) – 2014-10-10 09:21:15
我投了這個關閉作爲重複,鏈接的問題應該告訴你該怎麼做,爲什麼(改變'-laramdillo'和'-lhdf5'的順序)。無論哪種方式,我會稱這是一個在犰狳問題,因爲它取決於libhdf5,但沒有鏈接它。 – 2014-10-10 09:25:28
我明白了你的觀點,並且你鏈接的帖子的確很有意思,但是我懷疑有訂單問題,並且在發帖前檢查了這一點。問題實際上是不同的(見下面的答案)。 – JColin 2014-10-10 15:18:15