我想从 python 调用一些 pgcrypto 函数。即px_crypt。我似乎无法找出正确的目标文件来链接它。
这是我的代码:
#include <Python.h>
#include "postgres.h"
#include "pgcrypto/px-crypt.h"
static PyObject*
pgcrypt(PyObject* self, PyObject* args)
{
const char* key;
const char* setting;
if (!PyArg_ParseTuple(args, "ss", &key, &setting))
return NULL;
return Py_BuildValue("s", px_crypt(key, setting, "", 0));
}
static PyMethodDef PgCryptMethods[] =
{
{"pgcrypt", pgcrypt, METH_VARARGS, "Call pgcrypto's crypt"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initpypgcrypto(void)
{
(void) Py_InitModule("pypgcrypto", PgCryptMethods);
}
和 gcc 命令和输出:
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/home/ionut/github/postgres/contrib/ -I/usr/include/postgresql/9.4/server/ -I/usr/include/python2.7 -c pypgcrypto.c -o build/temp.linux-x86_64-2.7/pypgcrypto.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/pypgcrypto.o /usr/lib/postgresql/9.4/lib/pgcrypto.so -lpgport -lpq -o build/lib.linux-x86_64-2.7/pypgcrypto.so
错误是:
python -c "import pypgcrypto; print pypgcrypto.pgcrypt('foo', 'bar')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: /usr/lib/postgresql/9.4/lib/pgcrypto.so: undefined symbol: InterruptPending