This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

G++ link command line




Hello,
I have a problem with linking -lstdc++.so in the correct order.
The system conserned is a DG/UX unix. The system's programming 
manual clearly points out that in order to initialize -lc
reentrant -lthread should be put in front and should be 
_NO_ other .so libraries between them. So we need to have a command
(link) line as 

  ALL OTHER shared LIBS (-lgcc) -lthread -lc. 

My problem is when linking with c++ (or g++). Seems that a link command
line as (using either ld or g++ or c++)

  ALL OTHER LIBS ... -lthread -lstdc++ -lm -lc

will make the simplest C++ executable (eg Print Hello) to dump core.
I think this is because the -lthread initializes wrongly -lc. Analyzing
the core with gdb we could not find anything wrong in libstdc++. The core
is coming from libc and in particular from libc_init function.

On the contrary the link line  

  ALL OTHER LIBS ... -lstdc++ -lm -lthread -lc is OK.

Now I have add for some time an option -pthread that will do a

   ... -lthread -lc (instead -lc).

i.e. change actually the LIB_SPEC.
So if we link with gcc (not c++,g++) as 

 gcc -v -pthread .....

  we will see ..... -lgcc -lthread -lc

  (instead of -lgcc -lc)

which is exactly what we want for DG/UX.  

With c++ however (taking in acount the above problem with -lstdc++)

 c++ -v -pthread ... will produce a final link line as 

 ... -lstdc++ -lm -lgcc -lthread -lc 

which is fine again! (as it is the normal link ... -lstdc++ -lm 
-lgcc -lc).

But, if for example we link a line as 

 c++ files -o .... -lthread

so -lthread is manually put in the link line, and hence before -lstdc++,
we have a core! Even if we use c++ -v -pthreads i.e. a command
  
 ... -lthread -lstdc++ -lm -lgcc -lthread -lc 

the -lthread before -lstdc++ tries to initialize wrongly -lc
and I get a core. Such a command link line can be created for
example from a GNU configure script that detects -lthread and 
mark it as one of the OS libs. So it will be certainly in the c++
command line before the "internal -lstdc++. 
If I want to find a way to have a universal c++ linking comamnd linking ,
and not using ld manually  I need to be able to single out -lthread and
put it after -lstdc++. That seems to make things work OK. Any idea how
to do that?

Regards,
T.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]