public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: C++ Static Variable Initialization
@ 2001-09-15 17:12 Marcel Ruff
  0 siblings, 0 replies; 5+ messages in thread
From: Marcel Ruff @ 2001-09-15 17:12 UTC (permalink / raw)
  To: gcc

 > Thanks for your response. I do not have a main() program. I am creating a
 > shared library using g++. This shared library gets called from an 
existing
 > commercial application hence I do not have control over it.

Hi,

i have the same problem.

i am using Linux 2.4.4-4 with JDK 1.3.1 and egcs 2.95.3

I want to call one method in a native, shared C++ library from
Java, using JNI. So i have no main() program.

The C++ .so lib depends on other .so libs
which have many C++ classes which are
usually initialized automatically on startup before the
main() method (if i invoke
the old C++ application executable).

Now it seems, that the java System.load() which
loads the C++ shared library
does not call something like _main_()

I believe all my global C++ classes are
uninitialized - as i get this error:

--------------------------
   An unexpected exception has been detected in native code outside the VM.
   Unexpected Signal : 11 occurred at PC=0x405927d9
   Function 
name=__as__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0RCt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0
Library=/usr/lib/libstdc++-libc6.1-1.so.2
---------------------------

Is there any lowlevel main() in the Linux clib
which i can invoke manually?

thanks for any hint,

Marcel





As I understand the process, g++ emits magic during main() call to
initialize "static const" variables to their defined value. I have seen that
if the variables do not get initialized proeprly specifically if they are of
string type. I have found out that the reason for this is absence of main()
in my program, where these variables are supposed to be initialized.

After reading some reference books, I have found out that there may be a
compiler dependent procedure that I can call to initialize these variable.
Specifically since I am using g++ compiler, what function call can I make to
intialize all my static const string variables properly.





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

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

* RE: C++ Static Variable Initialization
@ 2001-08-17 14:29 Benjamin Kosnik
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Kosnik @ 2001-08-17 14:29 UTC (permalink / raw)
  To: gcc

Sarangdhar,

You may want to investigate using the -finit-priority flag, and
marking up your sources to indicate when specific items should be
initialized.

See this page:
http://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_6.html#SEC121

You might also want to scope the g++ testsuite for examples.

best,
benjamin

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

* RE: C++ Static Variable Initialization
@ 2001-08-17 13:45 Sarangdhar, NitinX
  0 siblings, 0 replies; 5+ messages in thread
From: Sarangdhar, NitinX @ 2001-08-17 13:45 UTC (permalink / raw)
  To: 'Alexandre Oliva', Sarangdhar, NitinX; +Cc: 'gcc@gcc.gnu.org'

Thanks for your response. I do not have a main() program. I am creating a
shared library using g++. This shared library gets called from an existing
commercial application hence I do not have control over it.

As I understand the process, g++ emits magic during main() call to
initialize "static const" variables to their defined value. I have seen that
if the variables do not get initialized proeprly specifically if they are of
string type. I have found out that the reason for this is absence of main()
in my program, where these variables are supposed to be initialized.

After reading some reference books, I have found out that there may be a
compiler dependent procedure that I can call to initialize these variable.
Specifically since I am using g++ compiler, what function call can I make to
intialize all my static const string variables properly. 





-----Original Message-----
From: Alexandre Oliva [ mailto:aoliva@redhat.com ]
Sent: Thursday, August 16, 2001 6:28 PM
To: Sarangdhar, NitinX
Cc: 'gcc@gcc.gnu.org'
Subject: Re: C++ Static Variable Initialization


On Aug 14, 2001, "Sarangdhar, NitinX" <nitinx.sarangdhar@intel.com> wrote:

> I have a C++ code with some static declarations. In the absence of main()
is
> there a way to initialize the statics properly? 

What appears to be the problem?  g++ does emit magic to get C++
globals initialized if you link in the gcc run-time object files,
which are implicitly linked in when you use g++ for linking.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* Re: C++ Static Variable Initialization
  2001-08-14 16:14 Sarangdhar, NitinX
@ 2001-08-16 18:30 ` Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2001-08-16 18:30 UTC (permalink / raw)
  To: Sarangdhar, NitinX; +Cc: 'gcc@gcc.gnu.org'

On Aug 14, 2001, "Sarangdhar, NitinX" <nitinx.sarangdhar@intel.com> wrote:

> I have a C++ code with some static declarations. In the absence of main() is
> there a way to initialize the statics properly? 

What appears to be the problem?  g++ does emit magic to get C++
globals initialized if you link in the gcc run-time object files,
which are implicitly linked in when you use g++ for linking.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* C++ Static Variable Initialization
@ 2001-08-14 16:14 Sarangdhar, NitinX
  2001-08-16 18:30 ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Sarangdhar, NitinX @ 2001-08-14 16:14 UTC (permalink / raw)
  To: 'gcc@gcc.gnu.org'

I have a C++ code with some static declarations. In the absence of main() is
there a way to initialize the statics properly? 

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-15 17:12 C++ Static Variable Initialization Marcel Ruff
  -- strict thread matches above, loose matches on Subject: below --
2001-08-17 14:29 Benjamin Kosnik
2001-08-17 13:45 Sarangdhar, NitinX
2001-08-14 16:14 Sarangdhar, NitinX
2001-08-16 18:30 ` Alexandre Oliva

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