如何在 Python 调试环境中构建扩展?

How to build an extension in Python debugging environment?

我正在尝试调试我编写的 Python 扩展。为了启用一些内存调试功能,我下载并构建了一个 Python 版本,它工作得很好。现在我正在尝试使用该环境构建我自己的包,但由于链接器未找到 libpython.x.x.a 静态库而失败。

building 'clusterline.cwsf.parser' extension
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -DPy_DEBUG -fPIC -I/usr/local/src/python/Python-3.6.8/Include -I/usr/local/src/python/Python-3.6.8 -c clusterline/cwsf/parser.c -o build/temp.linux-x86_64-3.6-pydebug/clusterline/cwsf/parser.o
gcc -pthread -shared build/temp.linux-x86_64-3.6-pydebug/clusterline/cwsf/parser.o -L. -lpython3.6d -o build/lib.linux-x86_64-3.6-pydebug/clusterline/cwsf/parser.cpython-36d-x86_64-linux-gnu.so
/usr/bin/ld: cannot find -lpython3.6d
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

请注意,图书馆存在。缺少的是“-L/usr/local/src/python/Python-3.6.8”链接器标志。为什么不在那里,如何到达那里?

$ ls /usr/local/src/python/Python-3.6.8/*.a

也许我只是被 Python 宠坏了 -- 通常调用 /path/to/venv/bin/python 时一切都会到位,为什么在这种情况下不起作用?我一定是遗漏了一些重要的东西。

你不能同时使用 ./configure --enable-shared 和 --with-pydebug。