Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: csd.cs.technion.ac.il: emild owned process doing -bs Date: Mon, 11 Mar 2002 23:48:44 +0200 (IST) From: Kohn Emil Dan X-X-Sender: To: Subject: g++/static members/DLL problem Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hello everyone, I would like to report a problem with g++ static member initialization on cygwin. I have a class in which I have a static data member. The definition of that class resides in a DLL. That static member is initialized in the corresponding .cpp file. However when I access it from an application, I do not get the initialized value, instead I get just garbage. The following example illustrates the problem: $ cat test_dll.h #ifndef TEST_DLL_H #define TEST_DLL_H class Foo { public: static int bar; }; #endif $ cat test_dll.cpp #include "test_dll.h" int Foo::bar = 17; $ cat test_app.cpp #include #include "test_dll.h" int main() { printf("Foo::bar=%d\n",Foo::bar); return 0; } The compilation process goes OK: $ g++ -g -shared test_dll.cpp -o test_dll.dll emild AT TP600EDSL2 ~/junk/cygwin-g++ $ g++ -g -o test_app test_app.cpp test_dll.dll However, when I run it, I get: $ ./test_app.exe Foo::bar=1086858751 This means that the static member did not get initialized properly to 17. Playing around with gdb hints about the cause of the problem. If I try to display the address of Foo::bar, it reads something like: 0x401250 while if I look at the place the .DLL has been loaded using the info shared command reveals that the DLL has been loaded at 0x10000000 I seems that for some reason a copy of the static member is produced inside the executable and worse, that copy does not get properly initialized. I use the version of g++ that comes with the latest cygwin distribution (1.3.10) $ g++ -v Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs gcc version 2.95.3-5 (cygwin special) Any help will be greately appreciated. And the obligatory cygcheck -s -v -r output: Cygwin Win95/NT Configuration Diagnostics Current System Time: Mon Mar 11 23:45:46 2002 Windows 2000 Professional Ver 5.0 Build 2195 Service Pack 2 Path: C:\cygwin\usr\local\bin C:\cygwin\bin C:\cygwin\bin c:\WINNT\system32 c:\WINNT c:\WINNT\system32\WBEM c:\WINNT\SYSTEM32 c:\WINNT c:\WINNT\System32\Wbem SysDir: C:\WINNT\System32 WinDir: C:\WINNT HOME = `c:\home\emild' MAKE_MODE = `unix' PWD = `/cygdrive/c/home/emild' USER = `emild' ALLUSERSPROFILE = `C:\Documents and Settings\All Users' APPDATA = `C:\Documents and Settings\emild\Application Data' CLASSPATH = `C:\Program Files\Exceed.nt\hcljrcsv.zip;C:\Program Files\Exceed.nt' COMMONPROGRAMFILES = `C:\Program Files\Common Files' COMPUTERNAME = `TP600EDSL2' COMSPEC = `C:\WINNT\system32\cmd.exe' HOMEDRIVE = `C:' HOMEPATH = `\home\emild' LOGONSERVER = `\\TP600EDSL2' NUMBER_OF_PROCESSORS = `1' OLDPWD = `/usr/bin' OS2LIBPATH = `C:\WINNT\system32\os2\dll;' OS = `Windows_NT' PATHEXT = `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH' PROCESSOR_ARCHITECTURE = `x86' PROCESSOR_IDENTIFIER = `x86 Family 6 Model 5 Stepping 2, GenuineIntel' PROCESSOR_LEVEL = `6' PROCESSOR_REVISION = `0502' PROGRAMFILES = `C:\Program Files' PROMPT = `$P$G' PS1 = `\[\033]0;\w\007 \033[32m\]\u@\h \[\033[33m\w\033[0m\] $ ' SHLVL = `1' SYSTEMDRIVE = `C:' SYSTEMROOT = `C:\WINNT' TEMP = `c:\DOCUME~1\emild\LOCALS~1\Temp' TERM = `cygwin' TMP = `c:\DOCUME~1\emild\LOCALS~1\Temp' USERDOMAIN = `TP600EDSL2' USERNAME = `emild' USERPROFILE = `C:\Documents and Settings\emild' WINDIR = `C:\WINNT' _ = `/usr/bin/cygcheck' HKEY_CURRENT_USER\Software\Cygnus Solutions HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2 (default) = `/cygdrive' cygdrive flags = 0x00000022 HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2\/ (default) = `C:/cygwin' flags = 0x00000002 HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2\/usr/bin (default) = `C:/cygwin/bin' flags = 0x00000002 HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2\/usr/lib (default) = `C:/cygwin/lib' flags = 0x00000002 HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\Program Options HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2 HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\Program Options a: fd N/A N/A c: hd FAT32 5135Mb 100% CP UN d: cd N/A N/A C:/cygwin / user binmode C:/cygwin/bin /usr/bin user binmode C:/cygwin/lib /usr/lib user binmode . /cygdrive user binmode,noumount Found: C:\cygwin\bin\bash.exe Found: C:\cygwin\bin\cat.exe Found: C:\cygwin\bin\cpp.exe Found: C:\cygwin\bin\find.exe Found: C:\cygwin\bin\gcc.exe Found: C:\cygwin\bin\gdb.exe Found: C:\cygwin\bin\ld.exe Found: C:\cygwin\bin\ls.exe Found: C:\cygwin\bin\make.exe Found: C:\cygwin\bin\sh.exe 612k 2002/01/16 C:\cygwin\bin\cygxml2-2.dll - os=4.0 img=1.0 sys=4.0 "cygxml2-2.dll" v0.0 ts=2002/1/16 6:24 56k 2000/12/03 C:\cygwin\bin\cygbz21.0.dll - os=4.0 img=1.0 sys=4.0 "cygbz21.0.dll" v0.0 ts=2000/11/21 1:53 73k 2002/01/16 C:\cygwin\bin\cygexslt-0.dll - os=4.0 img=1.0 sys=4.0 "cygexslt-0.dll" v0.0 ts=2002/1/16 11:06 202k 2002/01/16 C:\cygwin\bin\cygxslt-1.dll - os=4.0 img=1.0 sys=4.0 "cygxslt-1.dll" v0.0 ts=2002/1/16 10:52 81k 2001/10/20 C:\cygwin\bin\cygitcl30.dll - os=4.0 img=1.0 sys=4.0 "cygitcl30.dll" v0.0 ts=2001/10/20 2:25 35k 2001/10/20 C:\cygwin\bin\cygitk30.dll - os=4.0 img=1.0 sys=4.0 "cygitk30.dll" v0.0 ts=2001/10/20 2:25 390k 2001/10/20 C:\cygwin\bin\cygtcl80.dll - os=4.0 img=1.0 sys=4.0 "cygtcl80.dll" v0.0 ts=2001/10/20 2:24 5k 2001/10/20 C:\cygwin\bin\cygtclpip80.dll - os=4.0 img=1.0 sys=4.0 10k 2001/10/20 C:\cygwin\bin\cygtclreg80.dll - os=4.0 img=1.0 sys=4.0 "cygtclreg80.dll" v0.0 ts=2001/10/20 2:24 623k 2001/10/20 C:\cygwin\bin\cygtk80.dll - os=4.0 img=1.0 sys=4.0 "cygtk80.dll" v0.0 ts=2001/10/20 2:25 19k 2002/02/20 C:\cygwin\bin\cyggdbm.dll - os=4.0 img=1.0 sys=4.0 "cyggdbm.dll" v0.0 ts=2002/2/20 5:05 21k 2001/06/20 C:\cygwin\bin\cygintl.dll - os=4.0 img=1.0 sys=4.0 "cygintl.dll" v0.0 ts=2001/6/20 19:09 22k 2001/12/13 C:\cygwin\bin\cygintl-1.dll - os=4.0 img=1.0 sys=4.0 "cygintl-1.dll" v0.0 ts=2001/12/13 11:28 45k 2001/04/25 C:\cygwin\bin\cygform5.dll - os=4.0 img=1.0 sys=4.0 "cygform5.dll" v0.0 ts=2001/4/25 7:28 26k 2001/04/25 C:\cygwin\bin\cygmenu5.dll - os=4.0 img=1.0 sys=4.0 "cygmenu5.dll" v0.0 ts=2001/4/25 7:27 156k 2001/04/25 C:\cygwin\bin\cygncurses++5.dll - os=4.0 img=1.0 sys=4.0 "cygncurses++5.dll" v0.0 ts=2001/4/25 7:29 226k 2001/04/25 C:\cygwin\bin\cygncurses5.dll - os=4.0 img=1.0 sys=4.0 "cygncurses5.dll" v0.0 ts=2001/4/25 7:17 15k 2001/04/25 C:\cygwin\bin\cygpanel5.dll - os=4.0 img=1.0 sys=4.0 "cygpanel5.dll" v0.0 ts=2001/4/25 7:27 35k 2002/01/09 C:\cygwin\bin\cygform6.dll - os=4.0 img=1.0 sys=4.0 "cygform6.dll" v0.0 ts=2002/1/9 8:03 20k 2002/01/09 C:\cygwin\bin\cygmenu6.dll - os=4.0 img=1.0 sys=4.0 "cygmenu6.dll" v0.0 ts=2002/1/9 8:03 175k 2002/01/09 C:\cygwin\bin\cygncurses++6.dll - os=4.0 img=1.0 sys=4.0 "cygncurses++6.dll" v0.0 ts=2002/1/9 8:03 202k 2002/01/09 C:\cygwin\bin\cygncurses6.dll - os=4.0 img=1.0 sys=4.0 "cygncurses6.dll" v0.0 ts=2002/1/9 8:03 12k 2002/01/09 C:\cygwin\bin\cygpanel6.dll - os=4.0 img=1.0 sys=4.0 "cygpanel6.dll" v0.0 ts=2002/1/9 8:03 17k 2001/06/28 C:\cygwin\bin\cyghistory4.dll - os=4.0 img=1.0 sys=4.0 "cyghistory4.dll" v0.0 ts=2001/1/7 6:34 108k 2001/06/28 C:\cygwin\bin\cygreadline4.dll - os=4.0 img=1.0 sys=4.0 "cygreadline4.dll" v0.0 ts=2001/1/7 6:34 20k 2002/01/13 C:\cygwin\bin\cyghistory5.dll - os=4.0 img=1.0 sys=4.0 "cyghistory5.dll" v0.0 ts=2002/1/13 3:27 121k 2002/01/13 C:\cygwin\bin\cygreadline5.dll - os=4.0 img=1.0 sys=4.0 "cygreadline5.dll" v0.0 ts=2002/1/13 3:27 22k 2002/01/16 C:\cygwin\bin\cygxsltbreakpoint-1.dll - os=4.0 img=1.0 sys=4.0 "cygxsltbreakpoint-1.dll" v0.0 ts=2002/1/16 11:05 40k 2001/11/21 C:\cygwin\bin\cygpcre.dll - os=4.0 img=1.0 sys=4.0 "cygpcre.dll" v0.0 ts=2001/11/22 0:15 39k 2001/11/21 C:\cygwin\bin\cygpcreposix.dll - os=4.0 img=1.0 sys=4.0 "cygpcreposix.dll" v0.0 ts=2001/11/22 0:15 50k 2002/01/20 C:\cygwin\bin\cygz.dll - os=4.0 img=1.0 sys=4.0 "cygz.dll" v0.0 ts=2002/1/20 21:41 35k 2002/02/04 C:\cygwin\bin\cygltdl-3.dll - os=4.0 img=1.0 sys=4.0 "cygltdl-3.dll" v0.0 ts=2002/2/4 3:56 751k 2002/02/25 C:\cygwin\bin\cygwin1.dll - os=4.0 img=1.0 sys=4.0 "cygwin1.dll" v0.0 ts=2002/2/25 18:14 Cygwin DLL version info: DLL version: 1.3.10 DLL epoch: 19 DLL bad signal mask: 19005 DLL old termios: 5 DLL malloc env: 28 API major: 0 API minor: 51 Shared data: 3 DLL identifier: cygwin1 Mount registry: 2 Cygnus registry name: Cygnus Solutions Cygwin registry name: Cygwin Program options name: Program Options Cygwin mount registry name: mounts v2 Cygdrive flags: cygdrive flags Cygdrive prefix: cygdrive prefix Cygdrive default prefix: Build date: Mon Feb 25 11:14:34 EST 2002 Shared id: cygwin1S3 Cygwin Package Information Last downloaded files to: C:\cygwin-install Last downloaded files from: http://planetmirror.com/pub/sourceware/cygwin Package Version ash 20020131-1 autoconf 2.52a-1 autoconf-devel 2.52-4 autoconf-stable 2.13-4 automake 1.5b-1 automake-devel 1.5-5 automake-stable 1.4p5-5 bash 2.05a-3 binutils 20011002-1 bison 1.33-1 byacc 1.9-1 bzip2 1.0.1-6 clear 1.0 compface 1.4-5 cpio 2.4.2 crypt 1.0-1 ctags 5.2-1 cvs 1.11.0-1 cygutils 0.9.9-1 cygwin 1.3.10-1 dejagnu 20010117-1 diff 0.0 expect 20010117-1 file 3.37-1 fileutils 4.1-1 findutils 4.1 flex 2.5.4-1 gawk 3.0.4-1 gcc 2.95.3-5 gdb 20010428-3 gdbm 1.8.0-4 gettext 0.10.40-1 gperf 0.0 grep 2.5g gzip 1.3.2-1 indent 2.2.7-2 libintl 0.10.38-3 libintl1 0.10.40-1 libncurses5 5.2-1 libncurses6 5.2-8 libreadline4 4.1-2 libreadline5 4.2a-1 libtool 20010531a-1 libtool-devel 20020202-1 libtool-stable 1.4.2-2 libxml2 2.4.13-1 libxslt 1.0.10-1 login 1.4-3 m4 0.0 make 3.79.1-5 mingw-runtime 1.2-1 mktemp 1.4-1 ncurses 5.2-8 openssl-devel 0.9.6c-2 patch 2.5-3 pcre 3.7-1 perl 5.6.1-2 pkgconfig 0.10.0-1 popt 1.6.2-1 rcs 5.7-2 readline 4.2a-1 sed 3.02-1 sh-utils 2.0-2 tar 1.13.19-1 termcap 20010825-1 terminfo 5.2-1 textutils 2.0.21-1 time 1.7-1 units 1.77-1 vim 6.0.93-1 w32api 1.2-1 which 1.5-1 zlib 1.1.3-7 Use -h to see help about each section Regards, Emil -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/