简体   繁体   中英

swig mysql: undefined symbol: mysql_init'

I am trying to create a swig package for python that offers mysql connectivity. But when I try to import the package in python I get the following error:

-> _mod = imp.load_module('_IMysqlConnection', fp, pathname, description)
(Pdb) s
ImportError: './_IMysqlConnection.so: undefined symbol: mysql_init'

I am creating the package using the following commands (probably this is where I am making a blunder)

$swig -c++ -python -o IMysqlConnection_wrap.cc IMysqlConnection.i
$ gcc -fPIC -c IMysqlConnection_wrap.cc -o IMysqlConnection_wrap.o -I /usr/include/python2.6/ `mysql_config --cflags` `mysql_config --libs`
g$ gcc -fPIC -c IMysqlConnection.cc -o IMysqlConnection.o -I . /usr/include/python2.6/ `mysql_config --cflags` `mysql_config --libs`
$ g++ -shared IMysqlConnection_wrap.o IMysqlConnection.o -o _IMysqlConnection.so

I am able to do mysql connectivity when I use this class (IMysqlConnection.cc) in C++ main.

Any help and guidance will me much appreciated.

You can use http://sourceforge.net/projects/mysql-python/

This does not exactly answer your connection though.

Solved: I was missing mysql_config --cflags mysql_config --libs while creating the shared library _IMysqlConnection.so

g++ -shared CMysqlConnection_wrap.o CMysqlConnection.o -o _CMysqlConnection.so mysql_config --cflags mysql_config --libs

Above command linked mysql library to the shared library _IMysqlConnection.so and it worked fine.

Thanks Ugo for your help :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM