<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.12.3">
</HEAD>
<BODY>
On Tue, 2007-06-05 at 08:10 -0500, Mike McCarty wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Mike McCarty wrote:</FONT>
<FONT COLOR="#000000">> I have some tools which I use on my machine, and which I wish</FONT>
<FONT COLOR="#000000">> also to use on my GF's machine. She runs Debian. I find that</FONT>
<FONT COLOR="#000000">> I cannot use images built on my machine, as it has later</FONT>
<FONT COLOR="#000000">> versions of the shared libs on it, and at program load time</FONT>
<FONT COLOR="#000000">> I get reports of missing shared objects. Surely there is a way to</FONT>
<FONT COLOR="#000000">> build my programs so that they do not depend on the SOs in</FONT>
<FONT COLOR="#000000">> this manner. I've read the man page for ld and for gcc, yet</FONT>
<FONT COLOR="#000000">> haven't managed to figure this out. I thought that using</FONT>
<FONT COLOR="#000000">> gcc -o hellostatic hello.c -Wl,-static might do the job, but</FONT>
<FONT COLOR="#000000">> this fails with</FONT>
<FONT COLOR="#000000">> </FONT>
<FONT COLOR="#000000">> /usr/bin/ld: cannot find -lgcc_s</FONT>
<FONT COLOR="#000000">> collect2: ld returned 1 exit status</FONT>
<FONT COLOR="#000000">> </FONT>
<FONT COLOR="#000000">> Somebody please explain to me how to build an image on my machine</FONT>
<FONT COLOR="#000000">> which will run on another distro.</FONT>

<FONT COLOR="#000000">More experimentation shows that this may have done it...</FONT>

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

<FONT COLOR="#000000">I tried several other things, but this is the one which made</FONT>
<FONT COLOR="#000000">the executable actually grow. Brief perusal of the map seems</FONT>
<FONT COLOR="#000000">to indicate that the libs got included into the image.</FONT>

</PRE>
</BLOCKQUOTE>
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.<BR>
<BR>
Regards,<BR>
Les H
</BODY>
</HTML>