ld for win32 alphabetical order dependence

Shane Blackett s.blackett@auckland.ac.nz
Sun Nov 10 19:36:00 GMT 2002


Hi,

Thankyou everyone for these great tools.
I couldn't find anyone reporting behaviour like this so I thought I
should provide an example....

I have am building a project which incorporates both perl and gtk.  We
have recently been developing a windows port and so I have been building
this using mingw, both in win32 and as a cross compile.  I had lots of
failures where the executable links but when run it reports a dialog...
	test_win32_link_fails.exe - Application Error
	The application failed to initialize properly (0xc0000005).  Click on
OK to terminate the application.

I gather this code is basically the number for an access violation. 
This is occuring in the initialisation before the 
program code is started.

So I spent some time trying to find out what causes this and discovered
that the executable seems fine if the full
path name of the perl library is alphabetically before the full pathname
of the glib library.  This behaviour is the same
in both the win32 native link and the cross compile from Mandrake 8.2. 
It does not seem to matter the order of the libraries
on the link line or the version of binutils (I have been using the most
recent mingw binutils I found as well as older
versions) or the versions of gcc (I tried many before I tracked my
problem to library names).

My current setup is 
	gcc 2.95.3-5 (mingw special) although I have tried up to 3.2
	ld 2.11.90 (20010704) although I tried much more up to date ones up to
2.13.90 which is the most recent on
http://sourceforge.net/projects/mingw/
	w32api 2.0
	mingw-runtime 2.2

Everything is compiled -fnative-struct (or in recent gcc's
-mms-bitfields)

Here are my two link lines, where libperl56.a and libaperl56.a are
identical and
one executable succeeds and the other fails.
We use only Windows 2000 here so this is the only version of Windows
that I have tried.

\\esp167 \c:/tmp/test_win32>make -f test_win32_link.make
gcc -v -o test_win32_link_fails.exe test_win32_link.o -L. -lglib-2.0.dll
-lperl56
Reading specs from c:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/specs
gcc version 2.95.3-5 (mingw special)

c:\dev\gcc\bin\..\lib\gcc-lib\mingw32\2.95.3-5\..\..\..\..\mingw32\bin\ld.exe
-
Bdynamic -o test_win32_link_fails.exe
c:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95
.3-5/../../../crt2.o -L.
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5 -Lc:/d
ev/gcc/bin/../lib/gcc-lib
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/../..
/../../mingw32/lib
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/../../.. tes
t_win32_link.o -lglib-2.0.dll -lperl56 -lmingw32 -lgcc -lmoldname
-lmsvcrt -luse
r32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmsvcrt
gcc -v -o test_win32_link_succeeds.exe test_win32_link.o -L.
-lglib-2.0.dll -lap
erl56
Reading specs from c:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/specs
gcc version 2.95.3-5 (mingw special)

c:\dev\gcc\bin\..\lib\gcc-lib\mingw32\2.95.3-5\..\..\..\..\mingw32\bin\ld.exe
-
Bdynamic -o test_win32_link_succeeds.exe
c:/dev/gcc/bin/../lib/gcc-lib/mingw32/2
.95.3-5/../../../crt2.o -L.
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5 -Lc
:/dev/gcc/bin/../lib/gcc-lib
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/..
/../../../mingw32/lib
-Lc:/dev/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-5/../../..
test_win32_link.o -lglib-2.0.dll -laperl56 -lmingw32 -lgcc -lmoldname
-lmsvcrt -
luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname
-lmsvcrt

I have made a zip available of the test_win32_link.c test_win32_link.o
test_win32_link.make
libperl56.a libaperl56.a perl56.dll libglib-2.0.dll.a libglib-2.0-0.dll
test_win32_link_succeeds.exe
and test_win32_link_fails.exe at my ftp site (1Mb)
ftp://ftp.esc.auckland.ac.nz/pub/blackett/test_win32.zip

Plus if you want to compile the c file you need the headers for perl and
gtk2
ftp://ftp.esc.auckland.ac.nz/pub/blackett/gtk2.zip
ftp://ftp.esc.auckland.ac.nz/pub/blackett/perl.zip

I am pretty ignorant about the win32 executable format and am unsure how
to figure
out what the difference is.

Thanks for any help people can provide.

Shane.



More information about the Binutils mailing list