Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: compile and link for multithread?
       [not found] <3470C14D.AA9D0B34@unisys.com>
@ 1997-11-18  5:00 ` Dave Butenhof
  0 siblings, 0 replies; only message in thread
From: Dave Butenhof @ 1997-11-18  5:00 UTC (permalink / raw)




--------------2EE1E5A2F708F463E1742944
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Bob Blum wrote:

> I'm trying to create a multithreaded executable on Dec Alpha with 4.0
> The executable is being linked with a shared library I also made.
>
> The shared library was made with
>
>     cc -pthread  -shared -lc -lm -lpthread -lpthreads

If you're using the POSIX thread interface, then you should use:

     cc -o <file>.so -pthread -shared -lm <file>.c

The "-pthread" takes care of the proper compile-time definitions and
libraries. In particular, -pthread supplies "-lpthread", in the proper
place in the list of libraries (right at the end, but before libc).
Also, libpthreads.so (-lpthreads) is used only for "legacy" code (using
the DCE thread [draft 4 posix] or CMA interfaces).

If you are using legacy interfaces, build with

     cc -o <file>.so -threads -shared -lm <file>.c

Also, when you link with cc, the driver automatically places -lc in the
proper place, which is way at the end of the list of libraries.
Including libraries in the wrong order can cause problems, although I'm
not entirely certain that's your trouble.

In cases where you can't (or don't want to) use -pthread or -threads,
-pthread essentially supplies -D_REENTRANT for compilation, and
"-lpthread -lmach -lexc" for linkage. Similarly, -threads supplies
-D_REENTRANT and -D_PTHREAD_USE_D4 for compilation, and "-lpthreads
-lpthread -lmach -lexc" for linkage. Note that these may change in the
future! While programs compiled and linked properly will continue to
work, programs that were linked with the wrong definitions, or with
libraries missing or out of order may NOT continue to work, and you may
also end up pulling in stuff that you no longer need, even after
rebuilding on later versions where dependencies have been trimmed. (For
example, prior to 4.0 you needed -lc_r, which is now identical to -lc,
and is no longer needed.)

> I'm making the executable with:
>
>     cc -pthread -lc -lpthread

Similarly, this should be just

     cc -pthread

> When I try and run the executable it tells me
>
>     executableFileName: /sbin/loader: Error: unresolved symbol in
> /usr/shlib/libc.so __ldr_data
>
>     other unresolved symbols are: _end, __Argc, and __Argv

Most likely, this is due to your premature inclusion of libc, and will
be solved by removing the unnecessary explicit -lc. (You need to specify
that only when you link with ld instead of cc!)

/---------------------------[ Dave Butenhof ]--------------------------\
| Digital Equipment Corporation                   butenhof@zko.dec.com |
| 110 Spit Brook Rd ZKO2-3/Q18       http://members.aol.com/drbutenhof |
| Nashua NH 03062-2698  http://www.awl.com/cseng/titles/0-201-63392-2/ |
\-----------------[ Better Living Through Concurrency ]----------------/



--------------2EE1E5A2F708F463E1742944
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Bob Blum wrote:
<BLOCKQUOTE TYPE=CITE>I'm trying to create a multithreaded executable on
Dec Alpha with 4.0
<BR>The executable is being linked with a shared library I also made.

<P>The shared library was made with

<P>&nbsp;&nbsp;&nbsp; cc -pthread&nbsp; -shared -lc -lm -lpthread -lpthreads</BLOCKQUOTE>
If you're using the POSIX thread interface, then you should use:
<UL>cc -o &lt;file>.so -pthread -shared -lm &lt;file>.c</UL>
The "-pthread" takes care of the proper compile-time definitions and libraries.
In particular, -pthread supplies "-lpthread", in the proper place in the
list of libraries (right at the end, but before libc). Also, libpthreads.so
(-lpthreads) is used only for "legacy" code (using the DCE thread [draft
4 posix] or CMA interfaces).

<P>If you are using legacy interfaces, build with
<UL>cc -o &lt;file>.so -threads -shared -lm &lt;file>.c</UL>
Also, when you link with cc, the driver automatically places -lc in the
proper place, which is way at the end of the list of libraries. Including
libraries in the wrong order can cause problems, although I'm not entirely
certain that's your trouble.

<P>In cases where you can't (or don't want to) use -pthread or -threads,
-pthread essentially supplies -D_REENTRANT for compilation, and "-lpthread
-lmach -lexc" for linkage. Similarly, -threads supplies -D_REENTRANT and
-D_PTHREAD_USE_D4 for compilation, and "-lpthreads -lpthread -lmach -lexc"
for linkage. Note that these may change in the future! While programs compiled
and linked properly will continue to work, programs that were linked with
the wrong definitions, or with libraries missing or out of order may NOT
continue to work, and you may also end up pulling in stuff that you no
longer need, even after rebuilding on later versions where dependencies
have been trimmed. (For example, prior to 4.0 you needed -lc_r, which is
now identical to -lc, and is no longer needed.)
<BLOCKQUOTE TYPE=CITE>I'm making the executable with:

<P>&nbsp;&nbsp;&nbsp; cc -pthread -lc -lpthread</BLOCKQUOTE>
Similarly, this should be just
<UL>cc -pthread</UL>

<BLOCKQUOTE TYPE=CITE>When I try and run the executable it tells me

<P>&nbsp;&nbsp;&nbsp; executableFileName: /sbin/loader: Error: unresolved
symbol in
<BR>/usr/shlib/libc.so __ldr_data

<P>&nbsp;&nbsp;&nbsp; other unresolved symbols are: _end, __Argc, and __Argv</BLOCKQUOTE>
Most likely, this is due to your premature inclusion of libc, and will
be solved by removing the unnecessary explicit -lc. (You need to specify
that only when you link with ld instead of cc!)
<PRE>/---------------------------[ Dave Butenhof ]--------------------------\
| Digital Equipment Corporation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; butenhof@zko.dec.com |
| 110 Spit Brook Rd ZKO2-3/Q18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://members.aol.com/drbutenhof">http://members.aol.com/drbutenhof</A> |
| Nashua NH 03062-2698&nbsp; <A HREF="http://www.awl.com/cseng/titles/0-201-63392-2/">http://www.awl.com/cseng/titles/0-201-63392-2/</A> |
\-----------------[ Better Living Through Concurrency ]----------------/</PRE>
&nbsp;</HTML>

--------------2EE1E5A2F708F463E1742944--




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-11-18  5:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <3470C14D.AA9D0B34@unisys.com>
1997-11-18  5:00 ` compile and link for multithread? Dave Butenhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox