【问题标题】:python - ctypes error with mysql cpython - mysql c的ctypes错误
【发布时间】:2014-10-02 02:30:02
【问题描述】:

我用 c 创建了一个库,但是当我在 python 中调用该库时显示以下错误:

Traceback (most recent call last):
  File "probrar_lib.py", line 6, in <module>
    lib = cdll.LoadLibrary('/home/msorjas/Documentos/pruebas_c/lib1.so')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/msorjas/Documentos/pruebas_c/lib1.so: undefined symbol: mysql_query

c 库,使用以下代码编译:

gcc -c -fPIC lib1.c
gcc -shared lib1.o -o lib1.so

因为它应该编译?

我用的是linux。

已解决:

gcc -c -fPIC lib1.c
gcc -shared lib1.o -o lib1.so $(mysql_config --libs) $(mysql_config --cflags)

【问题讨论】:

  • 您应该发布SOLVED 位作为答案,并接受它。

标签: python c linux


【解决方案1】:

你忘了告诉它要针对 MySQL 构建。

gcc -shared -lmysqlclient lib1.o -o lib1.so

【讨论】:

    【解决方案2】:
    gcc -c -fPIC lib1.c
    gcc -shared lib1.o -o lib1.so $(mysql_config --libs) $(mysql_config --cflags)
    

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      相关资源
      最近更新 更多