为什么 PyImport_ImportModule 在 python 3.7.2 中出现段错误?
Why does PyImport_ImportModule segfault in python 3.7.2?
在 c api 中导入 python 是否会导致其他任何人出现段错误?
#0 0x00007ffff7d7efc4 in PyUnicode_InternInPlace () from /usr/lib64/libpython3.7m.so.1.0
#1 0x00007ffff7d7f00e in PyUnicode_InternFromString () from /usr/lib64/libpython3.7m.so.1.0
#2 0x00007ffff7d2fb88 in PyImport_Import () from /usr/lib64/libpython3.7m.so.1.0
#3 0x00007ffff7d347bb in PyImport_ImportModule () from /usr/lib64/libpython3.7m.so.1.0
#4 0x00000000004005f0 in main () at test2.cpp:5
#include <Python.h>
int main()
{
PyImport_ImportModule("os");
}
我是不是做错了什么,或者这是一个错误?
我正在使用这些编译标志(只是 python3-config --cflags 和 --libs 的输出):
-I/usr/include/python3.7m -I/usr/include/python3.7m -Wno-unused-result -Wsign-compare -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DNDEBUG -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DOPENSSL_LOAD_CONF -fwrapv -lpython3.7m -lpthread -ldl -lutil -lm
据我了解,在 C/C++ 中嵌入 Python 需要您使用 Py_Initialize()
和 Py_Finalize()
函数。
在 c api 中导入 python 是否会导致其他任何人出现段错误?
#0 0x00007ffff7d7efc4 in PyUnicode_InternInPlace () from /usr/lib64/libpython3.7m.so.1.0
#1 0x00007ffff7d7f00e in PyUnicode_InternFromString () from /usr/lib64/libpython3.7m.so.1.0
#2 0x00007ffff7d2fb88 in PyImport_Import () from /usr/lib64/libpython3.7m.so.1.0
#3 0x00007ffff7d347bb in PyImport_ImportModule () from /usr/lib64/libpython3.7m.so.1.0
#4 0x00000000004005f0 in main () at test2.cpp:5
#include <Python.h>
int main()
{
PyImport_ImportModule("os");
}
我是不是做错了什么,或者这是一个错误?
我正在使用这些编译标志(只是 python3-config --cflags 和 --libs 的输出):
-I/usr/include/python3.7m -I/usr/include/python3.7m -Wno-unused-result -Wsign-compare -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DNDEBUG -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DOPENSSL_LOAD_CONF -fwrapv -lpython3.7m -lpthread -ldl -lutil -lm
据我了解,在 C/C++ 中嵌入 Python 需要您使用 Py_Initialize()
和 Py_Finalize()
函数。