public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* global string object in a shared library
@ 2003-08-28  4:07 Tomas Varsavsky
  0 siblings, 0 replies; only message in thread
From: Tomas Varsavsky @ 2003-08-28  4:07 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm having problems using a global string in my shared library. The source 
file looks something like this:

---------
#include <string>
...
...
string myString;
...
...
int myFunction()
{
...
...
   myString = "Hello World";
...
...
}
---------

My main() just calls the function myFunction in the shared lib. I get a 
segmentation fault on the line 

	myString = "Hello World"

Backtrace points at line 154 of basic_string.h, which reads:

        bool
        _M_is_shared() const
        { return _M_references > 0; }  <--- line 154


I compile with -fpic, -shared and -g with version 3.2.2 of g++ in HP-UX 10.20 
to create a shared library, which end up looking like this:

[ASAC SDP 2.3] snapadm@sdp2 188: chatr libauc.sl
libauc.sl: 
         shared library 
         shared library dynamic path search:
             SHLIB_PATH     disabled  second 
             embedded path  enabled   first  /opt/sybase/opt/TWWfsw/gcc322/lib
         shared library list:
             dynamic   /opt/sybase/DS/0/lib/libsybdb.sl
             dynamic   /usr/lib/libnsl_s.1
             dynamic   /opt/sybase/opt/TWWfsw/gcc322/lib/libstdc++.sl.5
             dynamic   /usr/lib/libM.1
             dynamic   /opt/sybase/opt/TWWfsw/gcc322/lib/libgcc_s.sl
         shared vtable support disabled
         static branch prediction disabled
         kernel assisted branch prediction enabled
         lazy swap allocation disabled
         text segment locking disabled
         data segment locking disabled
         data page size: 4K
         instruction page size: 4K

If I write a similar program using int instead of string then it all works ok 
so I think the problem _is_ with the string class, or the way that I'm using 
it.

I suspect it's something to do with the global object not being 
constructed/allocated when my library loads because if I change the line 

string myString;

to

string myString = "test";

And then use gdb to set a breakpoint somewhere in myFunction() and do:

(gdb) p myString
$1 = {static npos = <incomplete type>, 
  _M_dataplus = {<allocator<char>> = {<No data fields>}, _M_p = 0x0}, 
  static _S_empty_rep_storage = {0, 0, 0, 0}}

It seems to not be allocated/assigned.

What am I doing wrong? Any ideas?

Thanks for your help.

Regards,

Tom

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

only message in thread, other threads:[~2003-08-28  4:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-28  4:07 global string object in a shared library Tomas Varsavsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).