global const variable not getting assigned properly

Chad Scholes cscholes@novell.com
Fri Dec 8 23:15:00 GMT 2006


So, I have found a little more information:

I have a Shared Library.  In that library is defined a number of static classes and const variables (they are global variables).  We need them to be static and/or const so they get loaded only once and everyone can reference them.

If I create an exe and reference any of those static classes or const (defined in the Shared Library) everything is fine.  However,  If I create a shared library that then calls any of the static classes or consts (defined in the other shared library) then none of the statics or consts are initialized.

I am linking the other library at Link time with the -lsoname parameter.  Do you know why they are not getting initialized?  If I call dlopen instead will that help solve this problem?  Is there something I can set to get those initialized before I use them?

I am using g++ version 4.0.2 on Suse 10.  I also get the same results compiling with  g++ (GCC) 4.1.0 (SUSE Linux).

Thanks!!!!


>>> John Love-Jensen <eljay@adobe.com> 12/08/06 5:44 AM >>>
Hi Chad,

> Any idea why it is 0 when using wcslen?  And any idea why I'm not even getting
> an error to notify me of the problem?

Works on my platform with my version of GCC with the BSD Standard C Library
(ISO/IEC 9899:1999 compliant).

I'm guessing its either your Standard C Library or your version of GCC or
your platform.

What version of Standard C Library are you using?

Who is the provider of your Standard C Library (e.g., GLibC)?

What version of GCC are you using?

What platform are you using?

Also, your code snippet and explanation of the behavior is nice, but could
you provide a short complete code example that demonstrates the problem.
Maybe its something simple like you used the incorrect header files (e.g.,
<wchar.h> instead of <cwchar>).

And could you provide the GCC command line that you used to compile your
short complete code example.

Thanks,
--Eljay




More information about the Gcc-help mailing list