Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ld cannot locate libpthread following -dynamic

3 views
Skip to first unread message

Tina Li

unread,
Aug 18, 2003, 3:53:30 PM8/18/03
to
Hello,

I'm statically linking libstdc++ on a SunOS 5.8 to solve compatibility
issues:

g++ foo foo.o bar.o -static -lstdc++ -dynamic -lm -lpthread

But it complains:

/usr/local/bin/ld: cannot find -lpthread
collect2: ld returned 1 exit status

I tried with -L, LD_LIBRARY_PATH, neither worked. I then tried to link
directly with /usr/lib/libpthread.so rather than putting it after -l, it did
compile fine, but when I ran foo, pthread_create() returned -1, which never
happen back in the dynamic-linking days.

So I'm stuck. Any insight?

Thanks much!

Tina


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Artie Gold

unread,
Aug 18, 2003, 4:56:41 PM8/18/03
to
Tina Li wrote:
> Hello,
>
> I'm statically linking libstdc++ on a SunOS 5.8 to solve compatibility
> issues:
>
> g++ foo foo.o bar.o -static -lstdc++ -dynamic -lm -lpthread

Try:

g++ -o foo foo .o bar.o -Wl,-Bstatic lstdc++ -Wl,-Bdynamic -lm -pthread

Using the -static option directly with g++ means `don't link with
dynamic libraries'; what you need is to send the option to the linker.

(I don't have a Sun box to test this on, but it should at least be
close. ;-). If you have a problem, add `-v' to see exactly what the
invocation of ld is doing.)

>
> But it complains:
>
> /usr/local/bin/ld: cannot find -lpthread
> collect2: ld returned 1 exit status
>
> I tried with -L, LD_LIBRARY_PATH, neither worked. I then tried to link
> directly with /usr/lib/libpthread.so rather than putting it after -l, it did
> compile fine, but when I ran foo, pthread_create() returned -1, which never
> happen back in the dynamic-linking days.
>

HTH,
--ag

>
>
>
>
>
>
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

--
Artie Gold -- Austin, Texas

Tina Li

unread,
Aug 19, 2003, 11:36:00 AM8/19/03
to
Hello,

Thanks for the help. But I thought having -dynamic would specify those I
want as dynamically linked. Anyway, I tried with

-Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lpthread

however it didn't work (most relevant output with -v on):

-Bstatic -lstdc++ -Bdynamic -lpthread -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s
-lgcc /usr/local/lib/gcc-lib/sparc-sunsolaris2.8/3.0.3/crtend.o
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crt.o

And ldd still shows libstdc++.so.3 being linked. Looks like libstdc++ is
"pre-coded" to be dynamically linked?

(full output is like this:

"Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/specs
Configured with:
../configure --with-as=/usr/local/bin/as --with-ld=/usr/local/bin/ld --enabl
e-libgcj
Thread model: posix
gcc version 3.0.3


/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/collect2 -V -R/usr/local/l
ib -Y P,/usr/ccs/lib:/usr/lib -Qy -o bThread_smp
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crt1.o
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crti.o
/usr/ccs/lib/values-Xa.o
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crtbegin.o -L/home/thli/ro
ot/misc//RAPTOR/osllib/lib -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0
.3 -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/../../..
/../sparc-sun-solaris2.8/lib -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib/
gcc-lib/sparc-sun-solaris2.8/3.0.3/../../.. foo.o
bar.o -Bstatic -lstdc++ -Bdynamic -lpthre
d -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/local/lib/gcc-lib/sparc-sunsolaris2.8/3.0.3/crtend.o
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crt.o")

If I switch the order of "-Bstatic -lstdc++" and "-Bdynamic -lpthread":

-Bdynamic -Bstatic -lstdc++ -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crtend.o
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/crtn.o

/usr/local/bin/ld: cannot find -lgcc_s


collect2: ld returned 1 exit status

Is there some configuration I need to tweak, some path I need to append,
etc. etc., to have -lstdc++ out of the -dynamic list?

Thanks again!

Tina, (distraught)


"Artie Gold" <arti...@austin.rr.com> wrote in message
news:3F413D5E...@austin.rr.com...

Paul Pluzhnikov

unread,
Aug 19, 2003, 4:05:00 PM8/19/03
to
"Tina Li" <tina_li23 AT hotmail DOT com> writes:

> Thanks for the help. But I thought having -dynamic would specify those I

If you want to pass '-dynamic' to the linker, you must preceed
it with '-Wl,' -- otherwise, '-d' is interpreted by g++.

> Anyway, I tried with
>
> -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lpthread
>
> however it didn't work (most relevant output with -v on):

Read this entire thread (there were several iterations) for a
working solution:

http://www.google.com/groups?threadm=dd7a565c.0306190732.5ecb0bd4%40posting.google.com

Cheers,
--
In order to understand recursion you must first understand recursion.

Tina Li

unread,
Aug 22, 2003, 2:35:23 PM8/22/03
to
It works! (*dancing about*) Thanks so much. This gotta be made an FAQ
question -- or maybe it already is.

Thanks again!

Tina


"Paul Pluzhnikov" <ppluz...@earthlink.net> wrote in message
news:u7k59v3l...@earthlink.net...

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----

0 new messages