gcc - 如何静态编译 Cython
问题描述
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)
为什么?
解决方案
推荐阅读
- encryption - 如何在我的代码中解决此范围错误?
- javascript - 将数组的字符串表示形式转换为 JS 数组
- ruby-on-rails - 我应该自己从文件系统中删除上传的文件吗?
- c - 将 char** 转换为 char* - 它会改变它指向的内容吗?
- c++ - C++ 包括类命名空间和类实例化
- sql-server - 使 SQL Server LocalDb 可移植
- sql-server-2008-r2 - 具有格式的 SQL Server 时间数据类型
- git - 如何以另一个用户身份提交和推送
- swift - AudioKit,将 AVAudioPCMBuffer 数组导出到带有淡入/淡出的音频文件
- javascript - JavaScript 让 Python 的 Selenium 陷入困境