2014-03-26 57 views
3

我試着寫一個非常短的腳本來打開一個hdf5文件,但它不起作用。HDF5 - C++ - 打開文件讀取內容失敗

#include <iostream> 
#include "H5Cpp.h" 

#ifndef H5_NO_NAMESPACE 
    using namespace H5; 
#endif 

const H5std_string FILE_NAME("testfile.h5"); 

int main (void) 

{ 

    H5File openFile(FILE_NAME, H5F_ACC_RDONLY); 

} 

我很確定我包含了hdf5庫和包含的路徑。 但無論如何我從連接器收到錯誤消息:

Invoking: GCC C++ Linker 
g++ -L/usr/local/pub/lib64 -L/usr/local/pub/lib -L/lib64 -L/usr/lib64 -o "HDF5_CPP" ./openfile.o 
./openfile.o: In function `main': 
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5check_version' 
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::FileAccPropList::DEFAULT' 
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::FileCreatPropList::DEFAULT' 
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::H5File::H5File(std::string const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)' 
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::H5File::~H5File()' 
collect2: error: ld returned 1 exit status 
make: *** [HDF5_CPP] Error 1 

誰能幫助? 謝謝!

+4

您需要將'-lhdf5_cpp -lhdf5'添加到您的構建命令中。 –

+0

我正在使用eclipse建設。我如何在這裏做到這一點? – smaica

+1

啊,我發現了!屬性 - C/C++構建 - 設置 - 鏈接器庫謝謝!有效 – smaica

回答

4

對於使用CMake的那些,這裏有一個例子:

(未定義的基準問題在最後一行解決)

find_package(HDF5 COMPONENTS C CXX HL REQUIRED) 
link_directories(${HDF5_LIBRARY_DIRS}) 
include_directories(${HDF5_INCLUDE_DIRS}) 
add_executable(convert_to_hdf5 src/convert_to_hdf5.cpp) 
target_link_libraries(convert_to_hdf5 ${HDF5_CXX_LIBRARIES}) 
0

我只是想留個紙條給其他人誰達到在未來這個地方,用同樣的問題所困擾:

如果你選擇使用g++用旗幟來編譯你的代碼,而不是HDF5提供的h5c++腳本,請確保您使用的標誌是從h5c++ -show而不是h5cc -show,因爲後者是直接C版本。