Compiling with NVCC

Hi,

I’m attempting to use the HDF5 library to read a texture to use with my CUDA code. I am NOT using Visual Studio. I try and compile with nvcc through the command line, but the paths are not being recognized and I have no idea of why. I attempted so many random things, nothing works. Here’s a few attempts and their output. I ran out of ideas! If anyone can point me to how these paths are intertwined and where it is looking for these libraries, I would appreciate it.

Thanks,

Simplified version of the code:
#include
#include <H5Cpp.h> // HDF5 library. Using v1.10.9 here.

int main() {
string H5_Filename = “mixing.h5”;

// Open HDF5 file handle, read only
H5File H5_File(H5_Filename.c_str(),H5F_ACC_RDONLY);
DataSet dataset = H5_File.openDataSet("Density_1000");
DataSpace dataspace = dataset.getSpace();

hsize_t rank;
hsize_t dims[1];
rank = dataspace.getSimpleExtentDims(dims); //
std::cout << "Data size: "<< dims[0] << std::endl; //
std::cout << "Data rank: "<< rank << std::endl; //

///I don't even know if this code works, because I can't compile the damn thing!

return 0;

}

Attempt 1 (no compiler options)

nvcc X.cu -o X
X.cu
X.cu(27): fatal error C1083: Cannot open include file: ‘H5Cpp.h’: No such file or directory

Attempt 2 (adding the HDF5 path)

nvcc X.cu -o CudaRaytracer11 -I “C:\Program Files\HDF_Group\HDF5\1.10.9\include” -I “C:\Program Files\HDF_Group\HDF5\1.10.9\bin” -I “C:\Program Files\HDF_Group\HDF5\1.10.9\lib”
X.cu
Creating library X.lib and object X.exp
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol H5open referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol H5check_version referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol "public: int __cdecl H5::DataSpace::getSimpleExtentDims(unsigned __int64 *,unsigned __int64 *)const " (?getSimpleExtentDims@DataSpace@H5@@QEBAHPEA_K0@Z) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: virtual __cdecl H5::DataSpace::~DataSpace(void)” (??1DataSpace@H5@@UEAA@XZ) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol "public: class H5::DataSet __cdecl H5::H5Location::openDataSet(char const *,class H5::DSetAccPropList const &)const " (?openDataSet@H5Location@H5@@QEBA?AVDataSet@2@PEBDAEBVDSetAccPropList@2@@Z) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol "public: virtual class H5::DataSpace __cdecl H5::DataSet::getSpace(void)const " (?getSpace@DataSet@H5@@UEBA?AVDataSpace@2@XZ) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: virtual __cdecl H5::DataSet::~DataSet(void)” (??1DataSet@H5@@UEAA@XZ) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: __cdecl H5::H5File::H5File(char const *,unsigned int,class H5::FileCreatPropList const &,class H5::FileAccPropList const &)” (??0H5File@H5@@QEAA@PEBDIAEBVFileCreatPropList@1@AEBVFileAccPropList@1@@Z) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: virtual __cdecl H5::H5File::~H5File(void)” (??1H5File@H5@@UEAA@XZ) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT” (?DEFAULT@FileAccPropList@H5@@2AEBV12@EB) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT” (?DEFAULT@FileCreatPropList@H5@@2AEBV12@EB) referenced in function main
tmpxft_00001a7c_00000000-19_CUDA_Raytracer_R11.obj : error LNK2019: unresolved external symbol “public: static class H5::DSetAccPropList const & const H5::DSetAccPropList::DEFAULT” (?DEFAULT@DSetAccPropList@H5@@2AEBV12@EB) referenced in function main
X.exe : fatal error LNK1120: 12 unresolved externals

You need to tell the linker where to find the HDF5 library. Something like

-L "C:\Program Files\HDF_Group\HDF5\1.10.9\lib" -lhdf5cpp -lhdf5

The -I (Include path) option is for the compiler to locate headers.The -L (Library path) option, combined with -l is for the linker to locate libraries.

G.

Hi, gheber, thank you for your reply. This did make some progress. I think your option -lhdf5cpp was not correct, since the name of the file is “hdf5_cpp.lib” in the lib folder (i.e., there’s an underscore). I changed it to -lhdf5_cpp and it produced less errors, but it is still not finding three functions, apparently. See current output below:

nvcc XXX.cu -o XXX -L “C:\Program Files\HDF_Group\HDF5\1.10.9\lib” -lhdf5_cpp -lhdf5 -I “C:\Program Files\HDF_Group\HDF5\1.10.9\include”
Creating library XXX.lib and object XXX.exp
tmpxft_0000682c_00000000-19_XXX.obj : error LNK2019: unresolved external symbol “public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT” (?DEFAULT@FileAccPropList@H5@@2AEBV12@EB) referenced in function main
tmpxft_0000682c_00000000-19_XXX.obj : error LNK2019: unresolved external symbol “public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT” (?DEFAULT@FileCreatPropList@H5@@2AEBV12@EB) referenced in function main
tmpxft_0000682c_00000000-19_XXX.obj : error LNK2019: unresolved external symbol “public: static class H5::DSetAccPropList const & const H5::DSetAccPropList::DEFAULT” (?DEFAULT@DSetAccPropList@H5@@2AEBV12@EB) referenced in function main
CudaRaytracer11.exe : fatal error LNK1120: 3 unresolved externals

Yes, hdf5_cpp.lib is the right name.

The linker appears to have trouble with a few static members, such as static const FileCreatPropList::FileCreatPropList &DEFAULT; I don’t know anything about the nvcc linking process and its defaults (static, dynamic, etc.), but someone else might have an idea.

G.

Hi, have you tried adding
using namespace H5; ?

Hi, bmribler, it wasn’t in the original code I submitted but I included it later - the errors that appear when compiling are the same as my last answer.

I suspect I’ll have to use another format for my files, unfortunately…

Did you use nvcc to build HDF5? If not I would start there…

Gosh, I don’t understand why this is so hard. Why are there so many dependencies? It is not straightforward to debug this, I’ve spent days already and can’t make any progress.

Is there a barebones implementation without any dependencies? Like just a single header file I can include in my project?

1 Like