This discussion is archived
2 Replies Latest reply: Nov 24, 2012 5:25 PM by Steve_Clamage RSS

correct switches for compile/link of pthreads app (Solaris 10)?

user13104769 Newbie
Currently Being Moderated
I am unsure about the compiler switches required for a pthreads application on Solaris 10 (Studio 12 compilers). The compiler man pages suggest using "-mt" when compiling to objects and "-mt -lpthread" when linking.
On the other hand, the Multithreaded Programming Guide states that from Solaris 10 on everything required is in libc, which could mean that compiling everything with -D_REENTRANT and linking without any switches related to threading might be sufficient.
The man page for CC says that libCrun needs -lthread, and therefore -lmt -lpthread is required, which confuses me.

Is "-mt -lpthread" the correct way?

Regards
D. Ruppert
  • 1. Re: correct switches for compile/link of pthreads app (Solaris 10)?
    Darryl Gove Newbie
    Currently Being Moderated
    Solaris 10 incorporated the threads library into libc, so you no longer need -lpthread. -mt is equivalent to -D_REENTRANT. So you just need -mt.

    Regards,

    Darryl.
  • 2. Re: correct switches for compile/link of pthreads app (Solaris 10)?
    Steve_Clamage Pro
    Currently Being Moderated
    Releases of Studio generally support multiple versions of Solaris, so the advice in the C++ Users Guide provides guidance on what will work on all supported platforms.

    When compiling with CC, or when linking an executable program using CC, you need -mt but not -lthread.
    When linking a shared library, no libraries are linked by default. You need to list explicitly every library that the shared library needs. In that case, you would need to add -lthread.

    If you link explicitly using ld instead of CC you must list all needed libraries. We strongly recommend against linking C++ programs using ld, because the command line needed depends on the CC options, and is difficult to get it right.

    For Posix threads, in general you need to add -lpthread, since pthreads are not the default.

    But as Darryl points out, on Solaris 10 and 11 the thread and pthread libraries are part of libc, so you don't need to list them.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points