Thank you very much Andy. The library problem is now solved. I checked the symbolic link to libdl.so.1, and it is fine. >From the test using your small c code c_link_test, it suggested something fundamental causing the difference between your and my results, so I checked my initial environment setting and found this line below in my .cshrc: setenv LD_OPTIONS -Bstatic Gees. Remove it and it goes. Thanks for all help from Andy and the group! Meng ----- Original Message ----- From: Andy Howell <AndyHowell@xxxxxxxxxxxxx> Date: Fri, 01 Aug 2003 01:13:43 -0500 To: Meng-Hsueh Chiang <mhchiang@xxxxxxxx> Subject: Re: Static library for gcc compiling > Meng, > > > I repeated the test you did, but things looked different. ldl was still not found. > > Still not sure what has caused the difference. Also, there is only libdl.so.1 > > not libdl.so on the search, is this correct? > > On my machine I see: > > ls -l /usr/lib/libdl* > lrwxrwxrwx 1 root root 12 Jul 10 10:14 /usr/lib/libdl.so > -> ./libdl.so.1 > -rwxr-xr-x 1 root bin 5292 Jan 25 2003 /usr/lib/libdl.so.1 > > Looks like you are missing a symbolic link to libdl.so.1 > > As root, try: > > cd /usr/lib > ln -s libld.so.1 libld.so > > Ah, wait a sec, below I see it looking for libdl.a where my test showed > it looking for libld.so followed libld.a. For dynamic linking, my > results seem correct. The linker first tries find a .so, and then a .a > > For static, just looking for libdl.a would make sense. In my trace I see > it looking for libdl.so.1, finding it, and opening it. Later it its > looking for libdl.so. I am guessing that this is happening in two > different contexts. In the first case, it is making use of the code in > the lib, while in the second it is trying to find it do resolve symbols. > > Try adding the above symlink and see what happens. Just be careful. If > you do something silly like renaming, you can bring your machine to a > grinding halt, unable to boot. I know. I've done it :) > > Andy > > > Thanks, > > Meng > > > > > > gcc -c c_link_test.c > > gcc -v -ldl c_link_test.o -o c_link_test > > > > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/specs > > Configured with: ../configure --disable-nls --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld > > Thread model: posix > > gcc version 3.2.3 > > /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/collect2 -V -Y P,/usr/ccs/lib:/usr/lib -Qy -o c_link_test /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crt1.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crti.o /usr/ccs/lib/values-Xa.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtbegin.o -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/../../.. -ldl c_link_test.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtend.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtn.o > > ld: Software Generation Utilities - Solaris Link Editors: 5.8-1.282 > > ld: fatal: library -ldl: not found > > ld: fatal: File processing errors. No output written to c_link_test > > collect2: ld returned 1 exit status > > > > truss -f -o out `which gcc` -v -ldl c_link_test.o -o c_link_test > > SAME MESSAGE ABOVE > > > > grep libdl out > > 6411: stat("/usr/lib/libdl.so.1", 0xFFBEE98C) = 0 > > 6411: open("/usr/lib/libdl.so.1", O_RDONLY) = 3 > > 6412: stat("/usr/lib/libdl.so.1", 0xFFBEE20C) = 0 > > 6412: open("/usr/lib/libdl.so.1", O_RDONLY) = 3 > > 6414: stat("/usr/lib/libdl.so.1", 0xFFBEDFB4) = 0 > > 6414: open("/usr/lib/libdl.so.1", O_RDONLY) = 6 > > 6414: open("/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/ccs/bin/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/ccs/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/../../../libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/openwin/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/openwin/lib/X11/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/lib/X11/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/openwin/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("~/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/X/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/openwin/lib/X11/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/ccs/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > 6414: open("/usr/lib/libdl.a", O_RDONLY) Err#2 ENOENT > > > > ----- Original Message ----- > > From: Andy Howell <AndyHowell@xxxxxxxxxxxxx> > > Date: Thu, 31 Jul 2003 23:01:15 -0500 > > To: Meng-Hsueh Chiang <mhchiang@xxxxxxxx> > > Subject: Re: Static library for gcc compiling > > > > > >>Meng-Hsueh Chiang, > >> > >> > >>I made a little test: > >> > >>#include <stdlib.h> > >>#include <stdio.h> > >>#include <dlfcn.h> > >> > >>main() > >>{ > >> dlopen("you wont find me", RTLD_NOW); > >> printf("Link me\n"); > >>} > >> > >>compiled it: > >> > >>gcc -c c_link_test.c > >> > >>Then linked it: > >> > >>gcc -v -ldl c_link_test.o -o c_link_test > >> > >>Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/specs > >>Configured with: ../configure --disable-nls --with-as=/usr/ccs/bin/as > >>--with-ld=/usr/ccs/bin/ld > >>Thread model: posix > >>gcc version 3.3 > >> /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/collect2 -V -Y > >>P,/usr/ccs/lib:/usr/lib -Qy -o c_link_test > >>/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/crt1.o > >>/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/crti.o > >>/usr/ccs/lib/values-Xa.o > >>/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/crtbegin.o > >>-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3 -L/usr/ccs/bin > >>-L/usr/ccs/lib > >>-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/../../.. -ldl > >>c_link_test.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc > >>/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/crtend.o > >>/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/crtn.o > >>ld: Software Generation Utilities - Solaris Link Editors: 5.8-1.279 > >> > >>ldd ./c_link_test > >> libdl.so.1 => /usr/lib/libdl.so.1 > >> libc.so.1 => /usr/lib/libc.so.1 > >> > >>Aside from different files names and extra libs in your case, I can't > >>see what the difference is. I have a newer compiler, 3.3, and you have a > >>newer linker. Collect2 searches for c++ constructors and creates a c > >>fiel containing them, compiles it, and then passes it to the linker. I > >>was trying to find what its options mean, but only came across the above > >> description. The only other thing I can suggest is run truss on gcc to > >>see what it is doing: > >> > >>truss -f -o out `which gcc` -v -ldl c_link_test.o -o c_link_test > >> > >>This traces the system calls that gcc and it children (-f) are making > >>and writes them to the file out (-o). > >> > >>"grep libdl out" shows where it is looking for libdl.so. Here is the > >>tail end of the search on my box: > >> > >>586: open("/usr/local/lib/libdl.so", O_RDONLY) Err#2 ENOENT > >>1586: open("/usr/local/lib/libdl.a", O_RDONLY) Err#2 ENOENT > >>1586: open("./libdl.so", O_RDONLY) Err#2 ENOENT > >>1586: open("./libdl.a", O_RDONLY) Err#2 ENOENT > >>1586: open("/usr/ccs/lib/libdl.so", O_RDONLY) Err#2 ENOENT > >>1586: open("/usr/ccs/lib/libdl.a", O_RDONLY) Err#2 ENOENT > >>1586: open("/usr/lib/libdl.so", O_RDONLY) = 7 > >> > >>Sorry I can't give you a better answer. Maybe someone on the list can help. > >> > >>Andy > >> > >> > >> > >> > >>>Andy, > >>> > >>>I tried the gcc command and made it all dynamic, so it should not have any issue with static -ldl. > >>>But it still said -ldl not found as follow (-v mode was used for your information). > >>>Could you please give me some clue? I sincerely appreciate that. > >>>Meng > >>> > >>>gcc -v -o spice3 spice3.o ./../../src/lib/misc.a -L/usr/openwin/lib -lXaw -lXt -lXext -lXmu -lX11 -lm -ltermlib -lsocket -lnsl -ldl > >>> > >>>Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/specs > >>>Configured with: ../configure --disable-nls --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld > >>>Thread model: posix > >>>gcc version 3.2.3 > >>> /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/collect2 -V -Y P,/usr/ccs/lib:/usr/lib -Qy -o spice3 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crt1.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crti.o /usr/ccs/lib/values-Xa.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtbegin.o -L/usr/openwin/lib -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/../../.. spice3.o ./../../src/lib/misc.a -lXaw -lXt -lXext -lXmu -lX11 -lm -ltermlib -lsocket -lnsl -ldl -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtend.o /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.3/crtn.o > >>>ld: Software Generation Utilities - Solaris Link Editors: 5.8-1.282 > >>>ld: fatal: library -ldl: not found > >>>ld: fatal: File processing errors. No output written to spice3 > >>>collect2: ld returned 1 exit status > >>> > >>> > >>>----- Original Message ----- > >>>From: Andy Howell <AndyHowell@xxxxxxxxxxxxx> > >>>Date: Thu, 31 Jul 2003 11:09:08 -0500 > >>>To: Meng-Hsueh Chiang <mhchiang@xxxxxxxx> > >>>Subject: Re: Static library for gcc compiling > >>> > >>> > >>> > >>>>Meng-Hsueh Chiang wrote: > >>>> > >>>> > >>>>>Thank you Andy for your helpful suggestion. > >>>>>It did finish the compiling. But when I ran the executable, core dumped. > >>>>> > >>>>>Somehow, long time ago, I could compile it on my previous machine with > >>>>>gcc -o spice spice3.o ./../../src/lib/misc.a -L/usr/lib -lXaw -lXt -lXext -lXmu -lX11 -lw -lm -ltermlib -lsocket -lnsl -ldl > >>>>>and got no complaint (I didn't see the problem before). > >>>> > >>>>Ok, no directives on the compile command to make it static, so its all > >>>>dynamic. Looks fine. > >>>> > >>>> > >>>> > >>>>>ldd spice > >>>>> libXaw.so.5 => /usr/lib/libXaw.so.5 > >>>>> libXt.so.4 => /usr/lib/libXt.so.4 > >>>>> libXext.so.0 => /usr/lib/libXext.so.0 > >>>>> libXmu.so.4 => /usr/lib/libXmu.so.4 > >>>>> libX11.so.4 => /usr/lib/libX11.so.4 > >>>>> libw.so.1 => /usr/lib/libw.so.1 > >>>>> libm.so.1 => /usr/lib/libm.so.1 > >>>>> libcurses.so.1 => /usr/lib/libcurses.so.1 > >>>>> libsocket.so.1 => /usr/lib/libsocket.so.1 > >>>>> libnsl.so.1 => /usr/lib/libnsl.so.1 > >>>>> libdl.so.1 => /usr/lib/libdl.so.1 > >>>>> libc.so.1 => /usr/lib/libc.so.1 > >>>>> libSM.so.6 => /usr/lib/libSM.so.6 > >>>>> libICE.so.6 => /usr/lib/libICE.so.6 > >>>>> libdga.so.1 => /usr/openwin/lib/libdga.so.1 > >>>>> libmp.so.2 => /usr/lib/libmp.so.2 > >>>>> /usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1 > >>>>> > >>>>>But now with Xlinker (as you suggeted in order to overcome -ldl issue) > >>>>>gcc -o spice spice.o ./../../src/lib/misc.a -L/usr/lib -lXaw -lXt -lXext -Bstatic -lXmu -Bdynamic -lX11 -lm -ltermlib -lsocket -lnsl -Xlinker -B -Xlinker dynamic -ldl -Xlinker -B -Xlinker static > >>>>> > >>>>>ldd spice > >>>>> libdl.so.1 => /usr/lib/libdl.so.1 > >>>> > >>>>Hmm, thats kind of wierd. I would have expected lib Xmu to be static and > >>>>everything else to be dynamic. Try -v on the compile line, I think that > >>>>shows what it being passed to the linker. > >>>> > >>>> > >>>> > >>>>>The library list is a lot shorter. Seems strange? Could you please give me some clues? > >>>>>Also, what would be causing the -ldl issue for my new system ? I know the SunOS, and gcc > >>>>>are different. > >>>> > >>>>I have made Solaris 5.8 binaries with mixed dynamic and static libs, so > >>>>I know that it works. The trick is getting options in the right order... > >>>> > >>>>Andy > >>>> > >>>> > >>>> > >>>>>Thanks a lot, > >>>>>Meng > >>>>> > >>>>>----- Original Message ----- > >>>>>From: Andy Howell <AndyHowell@xxxxxxxxxxxxx> > >>>>>Date: Wed, 30 Jul 2003 22:55:13 -0500 > >>>>>To: Meng-Hsueh Chiang <mhchiang@xxxxxxxx> > >>>>>Subject: Re: Static library for gcc compiling > >>>>> > >>>>> > >>>>> > >>>>> > >>>>>>Meng-Hsueh Chiang wrote: > >>>>>> > >>>>>> > >>>>>> > >>>>>>>I am getting undefined symbol (_dlclose, _dlopen, _dlsym) errors > >>>>>> > >>>>>>>from gcc compiling. > >>>>>> > >>>>>> > >>>>>>>If I added -ldl after gcc to resolve the issue, it said > >>>>>>>"ld: fatal: library -ldl: not found" > >>>>>>>because Sun didn't include a static version of `libdl.a' in /usr/lib. > >>>>>>>Does anyone know where I can get the file libdl.a for Solaris? > >>>>>>>or is there any workaround solution? > >>>>>>> > >>>>>>>Thanks a lot in advance! > >>>>>>> > >>>>>>> > >>>>>> > >>>>>>You should be able to add > >>>>>>-Xlinker -B -Xlinker dynamic -ldl -Xlinker -B -Xlinker static > >>>>>> > >>>>>>around it get it to work. Its been awhile since I've done it. You might > >>>>>>have to play with the positioning of this in the link line. > >>>>>> > >>>>>>Andy > >>>>>> > >>>>> > >>>>> > >>>>> > >>> > >> > > > > > >