public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Static initializer in shared libraries on Linux #2
@ 2001-09-16  6:18 Marcel Ruff
  2001-09-16  9:13 ` H . J . Lu
  2001-09-17  1:00 ` Marcel Ruff
  0 siblings, 2 replies; 4+ messages in thread
From: Marcel Ruff @ 2001-09-16  6:18 UTC (permalink / raw)
  To: gcc

Hi,

<more>
I forgot to mention that if i compile
xy.C to an executable, it runs fine,
but if xy.C is compiled to a shared library,
and invoked thru a java virtual machine ('no main()')
it fails as noted below
</more>

i have two .so libs, and get a sig 11 when
accessing a static string variable,
accessing a static variable of type char*
works fine:


InitTest.H
-----------
class InitTest
{
     public: static char * charName;
     public: static string stringName;
};
#if EXTERN_MAIN
char * InitTest::charName = "Hello charP";
string InitTest::stringName = string("Hello string");
#   endif
-----------

compile this into libInitTest.so



xy.C
------------
#define EXTERN_MAIN 1
....
// Runs fine:
cout << "C++: the charName=" << InitTest::charName << endl;
// Sig 11 - core dump:
cout << "C++: the stringName=" << InitTest::stringName << endl;
...
------------

compile this into xy.so
xy.C is run by a Java JVM using JNI.


Looking into the .so libs:
---------------------
nm -o *.so | grep charName
libxy.so:00028910 D _8InitTest.charName
libxy.so:0001bf60 t _GLOBAL_.D._8InitTest.charName
libxy.so:0001bf30 t _GLOBAL_.I._8InitTest.charName


nm -o *.so | grep stringName
libxy.so:0002d4c8 B _8InitTest.stringName
--------------------

The "string" class is never initialized whereas
the char* acts as expected!
Why?

Why is there no entry in libInitTest.so?

What do i have to change to get this running?

thanks for any help,

Marcel

-- 
Marcel Ruff
mailto:ruff@swand.lake.de
http://www.lake.de/home/lake/swand/
http://www.xmlBlaster.org


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Static initializer in shared libraries on Linux #2
  2001-09-16  6:18 Static initializer in shared libraries on Linux #2 Marcel Ruff
@ 2001-09-16  9:13 ` H . J . Lu
  2001-09-17  1:00 ` Marcel Ruff
  1 sibling, 0 replies; 4+ messages in thread
From: H . J . Lu @ 2001-09-16  9:13 UTC (permalink / raw)
  To: Marcel Ruff; +Cc: gcc

On Sun, Sep 16, 2001 at 03:18:26PM +0200, Marcel Ruff wrote:
> Hi,
> 
> <more>
> I forgot to mention that if i compile
> xy.C to an executable, it runs fine,
> but if xy.C is compiled to a shared library,
> and invoked thru a java virtual machine ('no main()')
> it fails as noted below

Please provide a small, complete testcase.


H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Static initializer in shared libraries on Linux #2
  2001-09-16  6:18 Static initializer in shared libraries on Linux #2 Marcel Ruff
  2001-09-16  9:13 ` H . J . Lu
@ 2001-09-17  1:00 ` Marcel Ruff
  2001-09-17  8:57   ` H . J . Lu
  1 sibling, 1 reply; 4+ messages in thread
From: Marcel Ruff @ 2001-09-17  1:00 UTC (permalink / raw)
  To: gcc, H . J . Lu

 > H . J . Lu wrote:
 > Please provide a small, complete testcase.

Here it is:


testCpp.zip contains

./testCpp/InitTest.C
./testCpp/xy.C
./testCpp/compile.sh
./testCpp/CppCaller.java


(The zip is 1873 bytes, i hope it is OK
  to send to your mailing list)

If you run the simple shell script on Linux

   ./compile.sh

it creates two shared libraries,
an executable xy.exe (which runs fine)
and compiles the java file (which fails on running).


thanks

Marcel




Marcel Ruff wrote:
> Hi,
> 
> <more>
> I forgot to mention that if i compile
> xy.C to an executable, it runs fine,
> but if xy.C is compiled to a shared library,
> and invoked thru a java virtual machine ('no main()')
> it fails as noted below
> </more>
> 
> i have two .so libs, and get a sig 11 when
> accessing a static string variable,
> accessing a static variable of type char*
> works fine:
> 
> 
> InitTest.H
> -----------
> class InitTest
> {
>     public: static char * charName;
>     public: static string stringName;
> };
> #if EXTERN_MAIN
> char * InitTest::charName = "Hello charP";
> string InitTest::stringName = string("Hello string");
> #   endif
> -----------
> 
> compile this into libInitTest.so
> 
> 
> 
> xy.C
> ------------
> #define EXTERN_MAIN 1
> ....
> // Runs fine:
> cout << "C++: the charName=" << InitTest::charName << endl;
> // Sig 11 - core dump:
> cout << "C++: the stringName=" << InitTest::stringName << endl;
> ...
> ------------
> 
> compile this into xy.so
> xy.C is run by a Java JVM using JNI.
> 
> 
> Looking into the .so libs:
> ---------------------
> nm -o *.so | grep charName
> libxy.so:00028910 D _8InitTest.charName
> libxy.so:0001bf60 t _GLOBAL_.D._8InitTest.charName
> libxy.so:0001bf30 t _GLOBAL_.I._8InitTest.charName
> 
> 
> nm -o *.so | grep stringName
> libxy.so:0002d4c8 B _8InitTest.stringName
> --------------------
> 
> The "string" class is never initialized whereas
> the char* acts as expected!
> Why?
> 
> Why is there no entry in libInitTest.so?
> 
> What do i have to change to get this running?
> 
> thanks for any help,
> 
> Marcel
> 



-- 
Marcel Ruff
mailto:ruff@swand.lake.de
http://www.lake.de/home/lake/swand/
http://www.xmlBlaster.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Static initializer in shared libraries on Linux #2
  2001-09-17  1:00 ` Marcel Ruff
@ 2001-09-17  8:57   ` H . J . Lu
  0 siblings, 0 replies; 4+ messages in thread
From: H . J . Lu @ 2001-09-17  8:57 UTC (permalink / raw)
  To: Marcel Ruff; +Cc: gcc

On Mon, Sep 17, 2001 at 10:00:04AM +0200, Marcel Ruff wrote:
> 
>  > H . J . Lu wrote:
>  > Please provide a small, complete testcase.
> 
> Here it is:
> 
> 
> testCpp.zip contains
> 
> ./testCpp/InitTest.C
> ./testCpp/xy.C
> ./testCpp/compile.sh
> ./testCpp/CppCaller.java
> 

Where is testCpp.zip?


H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-09-17  8:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-16  6:18 Static initializer in shared libraries on Linux #2 Marcel Ruff
2001-09-16  9:13 ` H . J . Lu
2001-09-17  1:00 ` Marcel Ruff
2001-09-17  8:57   ` H . J . Lu

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).