Davoud Taghawi-Nejad
Davoud Taghawi-Nejad

Reputation: 16776

external libraries with cython, result in ImportError

I import o few external libraries with cython:

cdef extern from "zmq.h" nogil:
int zmq_msg_init (zmq_msg_t *msg)
int zmq_msg_init_size (zmq_msg_t *msg, size_t size)
int zmq_bind (zmq_msg_t *msg, void *data,
    size_t size, zmq_free_fn *ffn, void *hint)  
...

And get the following error:

g++ -bundle -undefined dynamic_lookup -L/Users/taghawi/anaconda/envs/py3/lib -L/Users/taghawi/anaconda/envs/py3/lib -arch x86_64 build/temp.macosx-10.7-x86_64-3.6/processorgroup.o -L/Users/taghawi/anaconda/envs/py3/lib -lstdc++ -o /Users/taghawi/Dropbox/workspace/ABCEabsinth/processorgroup.cpython-36m-darwin.so
Traceback (most recent call last):
  File "start.py", line 1, in <module>
    from processorgroup import ProcessorGroup
ImportError: 
dlopen(/Users/taghawi/Dropbox/workspace/ABCEabsinth/processorgroup.cpython-36m-darwin.so, 2): Symbol not found: _zmq_bind
  Referenced from: /Users/taghawi/Dropbox/workspace/ABCEabsinth/processorgroup.cpython-36m-darwin.so
  Expected in: flat namespace
 in /Users/taghawi/Dropbox/workspace/ABCEabsinth/processorgroup.cpython-36m-darwin.so

Upvotes: 0

Views: 58

Answers (1)

Davoud Taghawi-Nejad
Davoud Taghawi-Nejad

Reputation: 16776

The problem is that if one uses a external library "zmq.h" in this case it needs to be specified in the compilation:

setup(
  name = 'cagent',
  ext_modules=cythonize([
 Extension('processorgroup', ['processorgroup.pyx'],
             language="c++",
             libraries=["stdc++", "zmq"],
             include_dirs=[numpy.get_include()],
            ),
          ]),
 cmdclass = {'build_ext': build_ext}
)

notice the "zmq" in 'libraries=["stdc++", "zmq"],'

Upvotes: 1

Related Questions