这是这个问题的后续问题:Minimal example of Python interpreter embedding segfaults。你知道吗
当我这样编译程序时:
gcc -fno-diagnostics-color -Wall -Wno-unused-function \
-I. -fPIC -g3 -shared -I/usr/include/python3.5m \
-I/usr/include/python3.5m -Wno-unused-result \
-Wsign-compare -g \
-fdebug-prefix-map=/build/python3.5-nLrllb/python3.5-3.5.3=. \
-fstack-protector-strong -Wformat -Werror=format-security \
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes \
-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib \
-lpython3.5m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic \
-Wl,-O1 -Wl,-Bsymbolic-functions ./main.o ./binparser.o \
-o protopy
大量的选项是由于运行:
/usr/bin/python3.5-config --cflags
和/usr/bin/python3.5-config --ldconfig
并尝试将它们合并到构建中(-fPIC
似乎是必需的,如果没有-shared
,它将不会链接,因为我认为,这是唯一可以链接到Python库的方法。你知道吗
当我在GDB中运行编译后的程序时,main()
总是没有参数。不管我是r foo bar
还是set args foo bar
。你知道吗
有什么想法吗?我不知道这里所有的gcc选项都做了什么,所以,也许是其中的一些?你知道吗
期望
gdb
在被调用的共享对象中设置一个有意义的断点是不合理的,就像它是一个可执行文件一样。如果对the linked question中描述的二进制文件使用strace
,则在对真正的可执行文件使用strace
时,通常从动态链接器看到的任何系统调用之前,您将看到立即segfault。你知道吗相关问题 更多 >
编程相关推荐