我不禁要问,为什么Python生成的ELF与原始源代码相比会很大。让我们看看最简单的代码helloworld。在user@linux:~/Python$ cat hello.py
print('Hello, World!')
user@linux:~/Python$
使用pyinstaller转换为ELF
^{pr2}$
新ELF格式user@linux:~/Python/dist$ ./hello
Hello, World!
user@linux:~/Python/dist$
user@linux:~/Python$ ls -lh hello.py
-rw-rw-r-- 1 user user 23 Dis 27 21:43 hello.py
user@linux:~/Python$
user@linux:~/Python/dist$ ls -lh hello
-rwxr-xr-x 1 user user 5.3M Dis 27 21:48 hello
user@linux:~/Python/dist$
如你所见,原始代码只有23个字节,而ELF要大得多。。。530万!!!在
让我们看另一个使用C的例子user@linux:~/C$ cat hello.c
#include
int main()
{
printf("Hello C World\n");
}
user@linux:~/C$
user@linux:~/C$ gcc hello.c -o helloC
user@linux:~/C$
user@linux:~/C$ ls -l helloC
-rwxrwxr-x 1 user user 8304 Dis 27 21:53 helloC
user@linux:~/C$
user@linux:~/C$ ./helloC
Hello C World
user@linux:~/C$
user@linux:~/C$ ls -l hello.c
-rw-rw-r-- 1 user user 65 Dis 27 21:52 hello.c
user@linux:~/C$
user@linux:~/C$ ls -lh helloC
-rwxrwxr-x 1 user user 8.2K Dis 27 21:53 helloC
user@linux:~/C$
比较Python code size = 27 bytes
Python ELF size = 5.3M
C code size = 65 bytes
C ELF size = 8.2K
有没有办法让尺寸变小?在