Re: Build for Generic Linux Solved?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2007-06-05 at 08:10 -0500, Mike McCarty wrote:
Mike McCarty wrote:
> I have some tools which I use on my machine, and which I wish
> also to use on my GF's machine. She runs Debian. I find that
> I cannot use images built on my machine, as it has later
> versions of the shared libs on it, and at program load time
> I get reports of missing shared objects. Surely there is a way to
> build my programs so that they do not depend on the SOs in
> this manner. I've read the man page for ld and for gcc, yet
> haven't managed to figure this out. I thought that using
> gcc -o hellostatic hello.c -Wl,-static might do the job, but
> this fails with
> 
> /usr/bin/ld: cannot find -lgcc_s
> collect2: ld returned 1 exit status
> 
> Somebody please explain to me how to build an image on my machine
> which will run on another distro.

More experimentation shows that this may have done it...

$ gcc -Wl,-M -o hellostatic hello.c -static 2>&1 | less
$ ls -l hello*
-rwxrwxr-x  1 jmccarty jmccarty   4716 Oct 17  2005 hello
-rw-rw-r--  1 jmccarty jmccarty    109 Jul 11  2005 hello.c
-rwxrwxr-x  1 jmccarty jmccarty 126458 Jul 11  2005 hello.exe
-rwxrwxr-x  1 jmccarty jmccarty 390403 Jun  5 08:07 hellostatic

I tried several other things, but this is the one which made
the executable actually grow. Brief perusal of the map seems
to indicate that the libs got included into the image.

That would seem to be the correct behavior for the -static option.  You should have seen the Make output on your console, which might have included the libraries that were linked to the code.  That is what the -M flag does for you.  I used to use it to generate a make file rule, but when I moved to IDE's I quite using Makefile systems, most of them have a predefined project file of one kind or another which performs the functions of Make or actually uses make in the background.  You can also use the -static option to only include the libgcc so that you aviod the issues of libgcc not being updated and not having the current calls implemented.  The other shared library calls seldom change, especially for a program like hello (I am assuming this is the "hello world" program.

Regards,
Les H

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux