help-gplusplus
[Top][All Lists]
Advanced

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

Re: statically linking pthreads


From: Paul Pluzhnikov
Subject: Re: statically linking pthreads
Date: Tue, 23 May 2006 10:34:34 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

VASILI3000@HOTMAIL.COM writes:

> i am trying to make a statically compiled executable of my application,

This is ill-advised: your executable is unlikely to work on any
system, other then the one you build it on.

> which uses the pthreads library facilities. 

Statically-linking threaded executables is even worse.

> $ g++ -static threads_static.c -o threads_static
>
> /home/vzafiropoulos/tmp/ccOsS8sA.o(.text+0x11): In function 
> `pthread_static_v::pthread_static_v()': > : undefined reference to 
> `pthread_create'

Obviously you need -pthread on the link line.

> i tried various combnations of "/usr/lib/libpthread.a" or "-pthread"
> into the compile/link line, but with no luck.

This should have worked. What were the errors?

> furthermore, dynamically linking the code has positive results.

Dynamic linking is what you *should* do, but static linking with

 $ g++ -static threads_static.c -o threads_static -pthread

should have also worked (as in "produced correctly working but
extremely non-portable executable").

> i am starting to suspect that i have a big problem with
> glibc/pthreads/stdlibc++ configuration...

I just tried 'g++ -static -pthread ...' on MDK-10, and came back with:
/usr/bin/ld: cannot find -lstdc++

If that's what you got, you need to install archive version of
libstdc++ (this has nothing to do with pthreads -- you wouldn't
be able to link any C++ program with -static if you don't have
libstdc++.a).

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]