test.py
:
print('Hello World!')
这里是python3.9-config --cflags:
-I/usr/include/python3.9 -I/usr/include/python3.9 -Wno-unused-result -Wsign-compare -g -ffile-prefix-map=/build/python3.9-RNBry6/python3.9-3.9.2=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall
这里--ldflags:
-L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -L/usr/lib -lcrypt -lpthread -ldl -lutil -lm -lm
我是这样编译 test.c 文件的:
gcc -c test.c -I/usr/include/python3.9/ -L/usr/lib/python3.9/ -lpython3.9 -o test.o --verbose
gcc -L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -L/usr/lib -lcrypt -lpthread -ldl -lutil -lm -lm -Wl,-no-as-needed -Bstatic -lpython3.9 -Wl,-Bdynamic -Wl,-as-needed -I/usr/include/python3.9 -I/usr/include/python3.9 -Wno-unused-result -Wsign-compare -g -ffile-prefix-map=/build/python3.9-RNBry6/python3.9-3.9.2=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall test.o -o test -Wl,-verbose
编译没有错误。但现在我明白了:
ldd ./test
linux-vdso.so.1 (0x00007ffde2bb3000)
libpython3.9.so.1.0 => /lib/x86_64-linux-gnu/libpython3.9.so.1.0 (0x00007fc183550000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc183388000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fc183358000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc183338000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc183310000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc183308000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fc183300000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc1831b8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc183b00000)
为什么?