Hdf5 and Python's C extensions : undefined symbol: H5T_NATIVE_DOUBLE_g

Hello, new user here both on the forum and HDF5, I hope the post is on topic and up to this comunity’s standards.
I was working on a C python extension for which I need the HDF5 library.

I’am working in a conda environment, using python 3.7.4. The HDF5 library is downloadable here. My version is a pre-built shared library (hdf5-1.12.0-linux-centos7-x86_64-shared-production).

I’ve downloaded, unpacked and moved all the file in the env/ directory of my project, naming it hdf5_shared.

My C extension as of now is quite small but rather prolix beein C code, so I will post the smallest fragment reproducing the error omitting the methodDef, moduleDef and PyMODINIT_FUNC parts of the code.

static PyObject* myFunction(PyObject* self, PyObject* args){
    hid_t datatype_id;
    datatype_id = H5Tcopy(H5T_NATIVE_DOUBLE);
    return Py_BuildValue("s", "alive");
}

I then have a python setup file, setup.py in the same directory with the following code :

from distutils.core import setup, Extension
import os

hdf5_lib_path = os.path.join(os.getcwd(), '../../../env/hdf5_shared/include')

module = Extension(
	"batch_similarities",
	include_dirs = [hdf5_lib_path],
	#extra_compile_args=['-Wall -O0 -g'],
	sources = ["batch_similarities.c"]
)

setup(
	name = "batch_similarities",
	version = "1.0",
	description = "Computes similarities matrices in C",
	ext_modules = [module]
)

I finally build the extension using the following command :
python setup.py install

Which yields no errors.

When I try to execute a python script using my extension I get the following error :

ImportError: somePath/env/lib/python3.7/site-packages/batch_similarities.cpython-37m-x86_64-linux-gnu.so: undefined symbol: H5T_NATIVE_DOUBLE_g

I have no idea what’s causing the issue, looking around I’ve found some related posts (here, here, and here). They all seem to mention problems regarding compilation without a special flag, H5_BUILT_AS_DYNAMIC_LIB, causing the impossibility of using the library as a dynamic library.

I’ve tried adding a macro definition and a bunch of other stuff to my setup.py as follows :

module = Extension(
	"batch_similarities",
	include_dirs = [hdf5_inc_path],
	define_macros=[('H5_BUILT_AS_DYNAMIC_LIB', True)],
	runtime_library_dirs = [hdf5_lib_path],
	library_dirs=[hdf5_lib_path],
	#extra_compile_args=['-Wall -O0 -g'],
	sources = ["batch_similarities.c"]
)

But none of the above combinations helped.

I’m not expert enough to understand it on my own so any help on how to solve the issue and any reference to material/topics to understand the issue better are welcome. Thanks a lot for reading all this.

flipbosco

      [Flipbosco](https://forum.hdfgroup.org/u/flipbosco)




    April 20

Hello, new user here both on the forum and HDF5, I hope the post is on topic and up to this comunity’s standards.

I was working on a C python extension for which I need the HDF5 library.

I’am working in a conda environment, using python 3.7.4. The HDF5 library is downloadable here. My version is a pre-built shared library (hdf5-1.12.0-linux-centos7-x86_64-shared-production).

I’ve downloaded, unpacked and moved all the file in the env/ directory of my project, naming it hdf5_shared.

My C extension as of now is quite small but rather prolix beein C code, so I will post the smallest fragment reproducing the error omitting the methodDef, moduleDef and PyMODINIT_FUNC parts of the code.


    static PyObject* myFunction(PyObject* self, PyObject* args){ hid_t datatype_id; datatype_id = H5Tcopy(H5T_NATIVE_DOUBLE); return Py_BuildValue("s", "alive"); }

I then have a python setup file, setup.py in the same directory with the following code :


from distutils.core import setup, Extension import os hdf5_lib_path = os.path.join(os.getcwd(), '../../../env/hdf5_shared/include') module = Extension( "batch_similarities", include_dirs = [hdf5_lib_path], #extra_compile_args=['-Wall -O0 -g'], sources = ["batch_similarities.c"] ) setup( name = "batch_similarities", version = "1.0", description = "Computes similarities matrices in C", ext_modules = [module] )

I finally build the extension using the following command :

python setup.py install

Which yields no errors.

When I try to execute a python script using my extension I get the following error :

ImportError: somePath/env/lib/python3.7/site-packages/[batch_similarities.cpython-37m-x86_64-linux-gnu.so](http://batch_similarities.cpython-37m-x86_64-linux-gnu.so)
: undefined symbol: H5T_NATIVE_DOUBLE_g

I have no idea what’s causing the issue, looking around I’ve found some related posts (here, here, and here). They all seem to mention problems regarding compilation without a special flag, H5_BUILT_AS_DYNAMIC_LIB, causing the impossibility of using the library as a dynamic library.

I’ve tried adding a macro definition and a bunch of other stuff to my setup.py as follows :


	module = Extension( "batch_similarities", include_dirs = [hdf5_inc_path], define_macros=[('H5_BUILT_AS_DYNAMIC_LIB', True)],

See https://docs.python.org/3/distutils/setupscript.html#describing-extension-modules section 2.3.3.

Try:

define_macros=[(‘H5_BUILT_AS_DYNAMIC_LIB’, None)],