We help IT Professionals succeed at work.

Compiled size problem

muis2002
muis2002 asked
on
Medium Priority
280 Views
Last Modified: 2010-04-15
Hi,

I compiled the same C source in two linux machines, both machines are RedHat 9.0.

I installed the same GCC compiler and MySQL library.

But why the compiled size is very different ?

In machine 1, 18 KB .....

In machine 2, 180 KB .....

What could be wrong ?

Here is my compile script :

#!/bin/sh

echo "building $1"

gcc -o $1 $1.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lz

It's probably in the second machine, the gcc put all the library in the resulting binary ?

Anyone can give me any idea why this happen ?

Thanks
Comment
Watch Question

Top Expert 2005
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Yes, I found that the result of nm -u on both binary are different (see below).

But why this happen ? I installed the same way ... and I use the same compile script.

How can I configure this ? I meant to make it smaller ... like in the MACHINE_1

MACHINE_1 ---> binary size = 20 KB

$ nm -u cgi_a
atoi@@GLIBC_2.0
connect@@GLIBC_2.0
__errno_location@@GLIBC_2.0
exit@@GLIBC_2.0
fcntl@@GLIBC_2.0
getenv@@GLIBC_2.0
gethostbyname@@GLIBC_2.0
__gmon_start__
htons@@GLIBC_2.0
_Jv_RegisterClasses
__libc_start_main@@GLIBC_2.0
localtime@@GLIBC_2.0
mysql_close
mysql_fetch_row
mysql_init
mysql_num_rows
mysql_real_connect
mysql_real_query
mysql_store_result
printf@@GLIBC_2.0
select@@GLIBC_2.0
socket@@GLIBC_2.0
sprintf@@GLIBC_2.0
sscanf@@GLIBC_2.0
strcat@@GLIBC_2.0
strcmp@@GLIBC_2.0
strcpy@@GLIBC_2.0
strftime@@GLIBC_2.0
strlen@@GLIBC_2.0
strpbrk@@GLIBC_2.0
strtok@@GLIBC_2.0
time@@GLIBC_2.0


MACHINE_2 ---> binary size = 181 KB

$ nm -u cgi_a
atoi@@GLIBC_2.0
bcmp@@GLIBC_2.0
bzero@@GLIBC_2.0
chdir@@GLIBC_2.0
closedir@@GLIBC_2.0
close@@GLIBC_2.0
compress
connect@@GLIBC_2.0
endpwent@@GLIBC_2.0
__errno_location@@GLIBC_2.0
exit@@GLIBC_2.0
fclose@@GLIBC_2.1
fcntl@@GLIBC_2.0
fdopen@@GLIBC_2.1
fflush@@GLIBC_2.0
fgets@@GLIBC_2.0
fileno@@GLIBC_2.0
fopen64@@GLIBC_2.1
fprintf@@GLIBC_2.0
fputc@@GLIBC_2.0
fputs@@GLIBC_2.0
free@@GLIBC_2.0
__fxstat64@@GLIBC_2.2
getcwd@@GLIBC_2.0
getenv@@GLIBC_2.0
geteuid@@GLIBC_2.0
gethostbyname@@GLIBC_2.0
gethostbyname_r@@GLIBC_2.1.2
getlogin@@GLIBC_2.0
getpeername@@GLIBC_2.0
getpwnam@@GLIBC_2.0
getpwuid@@GLIBC_2.0
getrusage@@GLIBC_2.0
getservbyname@@GLIBC_2.0
__gmon_start__
htons@@GLIBC_2.0
inet_addr@@GLIBC_2.0
inet_ntoa@@GLIBC_2.0
_Jv_RegisterClasses
__libc_start_main@@GLIBC_2.0
localtime@@GLIBC_2.0
__lxstat64@@GLIBC_2.2
malloc@@GLIBC_2.0
memchr@@GLIBC_2.0
memcpy@@GLIBC_2.0
memmove@@GLIBC_2.0
__mempcpy@@GLIBC_2.0
open64@@GLIBC_2.1
opendir@@GLIBC_2.0
poll@@GLIBC_2.0
printf@@GLIBC_2.0
puts@@GLIBC_2.0
qsort@@GLIBC_2.0
readdir64@@GLIBC_2.2
read@@GLIBC_2.0
readlink@@GLIBC_2.0
realloc@@GLIBC_2.0
realpath@@GLIBC_2.3
select@@GLIBC_2.0
setsockopt@@GLIBC_2.0
shutdown@@GLIBC_2.0
signal@@GLIBC_2.0
socket@@GLIBC_2.0
sprintf@@GLIBC_2.0
sscanf@@GLIBC_2.0
__stpcpy@@GLIBC_2.0
strcat@@GLIBC_2.0
strchr@@GLIBC_2.0
strcmp@@GLIBC_2.0
strcpy@@GLIBC_2.0
strftime@@GLIBC_2.0
strlen@@GLIBC_2.0
strpbrk@@GLIBC_2.0
strrchr@@GLIBC_2.0
strstr@@GLIBC_2.0
strtok@@GLIBC_2.0
__strtol_internal@@GLIBC_2.0
symlink@@GLIBC_2.0
time@@GLIBC_2.0
uncompress
vsprintf@@GLIBC_2.0
write@@GLIBC_2.0
__xstat64@@GLIBC_2.2


Commented:
I found this in MACHINE_1 (binary size = 20 KB)

$ ldd cgi_a
        libmysqlclient.so.12 => /usr/lib/libmysqlclient.so.12 (0x4001c000)
        libz.so.1 => /usr/lib/libz.so.1 (0x40052000)
        libc.so.6 => /lib/libc.so.6 (0x40060000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x40187000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x401b3000)
        libm.so.6 => /lib/libm.so.6 (0x401c7000)
        libnss_files.so.2 => /lib/libnss_files.so.2 (0x401e8000)
        libnss_dns.so.2 => /lib/libnss_dns.so.2 (0x401f3000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x401f7000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

And in MACHINE_2 (binary size = 181 KB)

$ ldd cgi_a
        libz.so.1 => /usr/lib/libz.so.1 (0x4001d000)
        libc.so.6 => /lib/i686/libc.so.6 (0x4002c000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

But I verified all the libraries are exists .... how to configure GCC so it can dynamically link ?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
I think the two machines can be different in what libraries they contain:
Machine 1 has the MySQL and other development libraries installed,
Machine 2 has only the core glibc libraries.

Just to make it clear: Are there a libmysqlclient.so.12 on Machine 2, too?

Author

Commented:
Fixed. :) wrong search folder ...
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.