我们有一个使用 C++ 创建的 32 位 Gui 应用程序。我们将应用程序从 Solaris 移植到 Linux。我们面临的问题是
与 Solaris 相比,LINUX 中的库和可执行文件的大小非常大。
Red Hat Enterprise Linux 5.4 是我们使用的 Linux 版本。
请查找创建的示例动态库。我们想知道 LINUX 的以下行为是否正常。
假设我们创建了两个文件 test1.cc 和 test2.cc。两者都只有一行代码。
a-2720@N530 /data1/users/a-2720/samp :ls -lrt test1.cc test2.cc
-rw-rw-r-- 1 a-2720 mcs 21 May 18 06:16 test1.cc
-rw-rw-r-- 1 a-2720 mcs 21 May 18 06:16 test2.cc
a-2720@N530 /data1/users/a-2720/samp :cat test1.cc
#include<iostream.h>
a-2720@N530 /data1/users/a-2720/samp :cat test2.cc
#include<iostream.h>
因此文件中只有一行
我使用这些文件创建了一个共享库。
索拉瑞斯
CC -c -library=iostream -g -mt test1.cc
CC -c -library=iostream -g -mt test2.cc
CC -G -h libtestsolaris.so test1.o test2.o -o libtestsolaris.so -library=iostream
a-2720@N530 /data1/users/a-2720/samp :ls -lrt test1.o test2.o libtestsolaris.so
-rw-rw-r-- 1 a-2720 mcs 20944 May 18 06:16 test1.o
-rw-rw-r-- 1 a-2720 mcs 20944 May 18 06:16 test2.o
-rwxrwxr-x 1 a-2720 mcs 7384 May 18 06:16 libtestsolaris.so
Linux
CC -m32 -c -library=iostream -g -mt test1.cc
CC -m32 -c -library=iostream -g -mt test2.cc
CC -m32 -G -h libtestlinux.so test1.o test2.o -o libtestlinux.so -library=iostream
/data1/users/adarsh/samp :ls -lrt test1.o test2.o libtestlinux.so
-rw-r--r-- 1 adarsh ifo 20220 May 18 06:44 test1.o
-rw-r--r-- 1 adarsh ifo 20220 May 18 06:44 test2.o
-rwxr-xr-x 1 adarsh ifo 41680 May 18 06:44 libtestlinux.so
在这里我们可以看到Linux 共享库的大小比以前的solaris 大很多。请注意源文件
这些库是相同的。 我们的应用程序使用了数千个具有这些头文件的文件,因此在大小上出现了显着差异。
我们想知道这种大小差异是 LINUX 的正常行为。
系统详情
/data1/users/adarsh/samp :cat /etc/*-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
/data1/users/adarsh/samp :uname -a
Linux N280 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
最佳答案
-g
选项将为 add debugging information到可执行文件,这将增加其大小。同时打开 options that control various optimizations .
关于c++ - LINUX 中库/可执行文件的大小很大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053619/