argc总是z

2024-05-21 08:42:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这是这个问题的后续问题: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选项都做了什么,所以,也许是其中的一些?你知道吗


Tags: configbinincludeunused链接mainlibusr
1条回答
网友
1楼 · 发布于 2024-05-21 08:42:55

期望gdb在被调用的共享对象中设置一个有意义的断点是不合理的,就像它是一个可执行文件一样。如果对the linked question中描述的二进制文件使用strace,则在对真正的可执行文件使用strace时,通常从动态链接器看到的任何系统调用之前,您将看到立即segfault。你知道吗

相关问题 更多 >