Please note that LinuxExchange will be shutting down on December 31st, 2016. Visit this thread for additional information and to provide feedback.

HI All,

We have a 32bit Gui application created using C++. We ported the application from Solaris to Linux. Issue we are facing is the size of the library and executable is very large in LINUX compared to Solaris.

Red Hat Enterprise Linux 5.4 is the Linux version we using.

Please find a sample dynamic library created. We would like to know the following behavior of LINUX is normal or not.

Consider we created two files test1.cc and test2.cc. Both having a single line of code.

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>

Thus the files have only only one line inside them

I created a Shared library using these files.

SOLARIS

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

Here we can see that the Linux shared library are in much bigger size than solaris once. Please note that the source file for

these libraries are same. Our application uses thousand of files having these header files and hence a notable difference in size occurs.

We would like to know this size difference is a normal behavior of LINUX.

System Details

/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

Thanks in advance.

Sanush Chacko

asked 18 May '11, 23:47

1234567890's gravatar image

1234567890
2113
accept rate: 0%

edited 19 May '11, 20:32

Jazz's gravatar image

Jazz ♦
7811312




It seems to me that you're comping without optmization. -O2 should be the minimum in your case. -Os is another choice.

link

answered 23 May '11, 17:14

who_knows's gravatar image

who_knows
461
accept rate: 16%

Have you tried using another compiler like g++? g++ has a lot of optimization options, most notably -Os.

I haven't created shared libraries yet, so the following might not be correct or the best way to do it, but it might help you:

g++ -Os -fPIC -shared test1.cc -o test1.o
g++ -Os -fPIC -shared test2.cc -o test2.o
g++ -shared -Os test1.o test2.o -o libtest.so

ls -lA
-rwxr-xr-x  1 jazz users 5616 19. Mai 15:08 libtest.so
-rw-r--r--    1 jazz users   19 19. Mai 14:59 test1.cc
-rwxr-xr-x  1 jazz users 6500 19. Mai 15:09 test1.o
-rw-r--r--    1 jazz users   19 19. Mai 14:59 test2.cc
-rwxr-xr-x  1 jazz users 6500 19. Mai 15:03 test2.o


Furthermore, I changed

#include<iostream.h>

to

#include<iostream>

in the test-files. The difference is explained here.


You can also use strip! Strip can reduce the size of the object file by a significant amount, but debugging is hindered afterwards.


All this was done on the following x86_64 system:

Linux substitutedhostname 2.6.38-ARCH #1 SMP PREEMPT Fri May 13 09:24:47 CEST 2011 x86_64 Intel(R) Core(TM) i7 CPU M 620 @ 2.67GHz GenuineIntel GNU/Linux
link

answered 19 May '11, 09:25

Jazz's gravatar image

Jazz ♦
7811312
accept rate: 33%

edited 23 May '11, 11:45

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×90
×16
×1
×1

Asked: 18 May '11, 23:47

Seen: 2,704 times

Last updated: 23 May '11, 17:14

powered by OSQA