<p>That really sounds like incorrect .a builds. </p>
<div class="gmail_quote">On Jul 28, 2012 9:10 AM, "Charles Shapiro" <<a href="mailto:hooterpincher@gmail.com">hooterpincher@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The "diary.c" program compiles, links, and runs flawlessly to a shared<br>
library executable 18K in size. It uses readline(3) to get some stuff<br>
the user types in.<br>
<br>
So you'd _think_ that, given "/usr/lib/libreadline.a", the command:<br>
<br>
gcc -static -I. -lreadline -o diary diary.c<br>
<br>
Would create the statically linked "diary" executable. But in fact,<br>
on my ubuntu 10.10 system you get:<br>
<br>
/tmp/ccU5znZ0.o: In function `get_timecode':<br>
diary.c:(.text+0x65e): undefined reference to `readline'<br>
diary.c:(.text+0x6ef): undefined reference to `readline'<br>
/tmp/ccU5znZ0.o: In function `get_inputstring':<br>
diary.c:(.text+0x76b): undefined reference to `readline'<br>
collect2: ld returned 1 exit status<br>
<br>
After much manful struggle, I determined that I could only get the<br>
static-linked "diary" program to include readline if I disassembled<br>
the /usr/lib/libreadline.a library with ar(1), then explicitly named<br>
the .o files in the gcc command:<br>
<br>
cc -static -I. -lgpm -o diary-static diary.c readline-6.1/bind.o<br>
readline-6.1/callback.o readline-6.1/compat.o readline-6.1/complete.o<br>
readline-6.1/display.o readline-6.1/funmap.o readline-6.1/histexpand.o<br>
readline-6.1/histfile.o readline-6.1/history.o<br>
readline-6.1/histsearch.o . . .<br>
<br>
Alas, the same mechanism ( or lack of mechanism) also holds with the<br>
ncurses library and the gpm library, which libreadline requires. So<br>
after an immensely long gcc command line, I have a statically linked<br>
program which runs, and is only 1.3 MB in size.<br>
<br>
Has anyone else tried this with a less cumbersome method? I have<br>
verified that I can statically link the "hello world" example ( the<br>
shared object one is about 7K, and the static one is about 600), so I<br>
am pretty sure that libgcc.a is being properly referenced. All of the<br>
googling I have done seems to indicate that at the very least:<br>
<br>
gcc -static -lreadline -lgpm -lncurses -I. -o diary-test diary.c<br>
<br>
Should produce a statically linked diary-test file, given<br>
/usr/lib/libreadline.a, /usr/lib/libncurses.a, and /usr/lib/libgpm.a.<br>
But of course it never picks the readline object out of<br>
/usr/lib/libreadline.a, giving the same error message as above.<br>
If I tear everything into .o files with ar(1) and explicitly link<br>
those in, the linker works fine. Once I am over the linker troubles,<br>
the static-linked program seems to run. I am quite sure that gcc is<br>
seeing libreadline.a, since I get no kvetching about not being able to<br>
find a file, and I tried moving libreadline.a around and pointing to<br>
it in different places with no change in behavior.<br>
<br>
I am using:<br>
<br>
gcc -v<br>
Using built-in specs.<br>
Target: i686-linux-gnu<br>
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro<br>
4.4.4-14ubuntu5.1'<br>
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs<br>
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr<br>
--program-suffix=-4.4 --enable-shared --enable-multiarch<br>
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib<br>
--without-included-gettext --enable-threads=posix<br>
--with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib<br>
--enable-nls --with-sysroot=/ --enable-clocale=gnu<br>
--enable-libstdcxx-debug --enable-objc-gc --enable-targets=all<br>
--disable-werror --with-arch-32=i686 --with-tune=generic<br>
--enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu<br>
--target=i686-linux-gnu<br>
Thread model: posix<br>
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5.1)<br>
<br>
ld --version<br>
GNU ld (GNU Binutils for Ubuntu) 2.20.51-system.20100908<br>
<br>
-- CHS<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
</blockquote></div>