creating shared dlls yields undefined reference to `WinMain@16' in mingw 4.3

Daniel Walter d2walter@hotmail.com
Tue Dec 16 16:31:00 GMT 2008


It appears that libmingw.a is causing the problem, though this library can 
be linked to form a dll as long as no gcj object files are linked as well. 
Below are the results of the attempts to link with 'g++ -v' first with gcj 
objects which failed and the second time with only g++ objects.


g++ -shared -v ads\pdflink.o pdflib.a -lgcj -lws2_32 -o pdflib.dll
Using built-in specs.
Target: mingw32
Configured with: 
./gcc-4.3.0/configure --enable-languages=c,ada,c++,fortran,jav
a,objc,obj-c++ --disable-sjlj-exceptions --enable-shared --enable-libgcj --enabl
e-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enab
le-concept-checks --enable-version-specific-runtime-libs --build=mingw32 --with-
bugurl=http://www.mingw.org/bugs.shtml --prefix=/mingw --with-gmp=/mingw/src/gcc
/gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-mpfr-root --with-libiconv-prefix=/
mingw/src/gcc/libiconv-root
Thread model: win32
gcc version 4.3.0 20080305 (alpha-testing) mingw-20080502 (GCC)
COMPILER_PATH=c:/documents and settings/dan/my 
documents/programs/cygwin/home/da
n/ming/bin/../libexec/gcc/mingw32/4.3.0/;c:/documents and settings/dan/my 
docume
nts/programs/cygwin/home/dan/ming/bin/../libexec/gcc/;c:/documents and 
settings/
dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../.
/../../mingw32/bin/
LIBRARY_PATH=c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan
/ming/bin/../lib/gcc/mingw32/4.3.0/;c:/documents and settings/dan/my 
documents/p
rograms/cygwin/home/dan/ming/bin/../lib/gcc/;c:/documents and 
settings/dan/my do
cuments/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../../../m
ingw32/lib/;c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/
ming/bin/../lib/gcc/mingw32/4.3.0/../../../
COLLECT_GCC_OPTIONS='-shared' '-v' '-o' 'pdflib.dll' '-mtune=i386'
 c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/..
/libexec/gcc/mingw32/4.3.0/collect2.exe --shared -Bdynamic -e 
_DllMainCRTStartup
@12 --enable-auto-image-base -o pdflib.dll c:/documents and settings/dan/my 
docu
ments/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../../dllcrt
2.o c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin
/../lib/gcc/mingw32/4.3.0/crtbegin.o -Lc:/documents and settings/dan/my 
document
s/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0 -Lc:/documents 
and
settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/gcc -Lc:/docu
ments and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/gcc
/mingw32/4.3.0/../../../../mingw32/lib -Lc:/documents and settings/dan/my 
docume
nts/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../.. 
ads\pdfl
ink.o 
pdflib.a -lgcj -lws2_32 -lstdc++ -lmingw32 -lgcc -lmoldname -lmingwex -lms
vcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingw
ex -lmsvcrt c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/
ming/bin/../lib/gcc/mingw32/4.3.0/crtend.o
c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/../
lib/gcc/mingw32/4.3.0/../../../libmingw32.a(main.o):main.c:(.text+0xbd): 
undefin
ed reference to `WinMain@16'
collect2: ld returned 1 exit status





==========================================================================
g++ -shared -v dlltest.o -lgcj -lws2_32 -o outputdll.dll
Using built-in specs.
Target: mingw32
Configured with: 
./gcc-4.3.0/configure --enable-languages=c,ada,c++,fortran,jav
a,objc,obj-c++ --disable-sjlj-exceptions --enable-shared --enable-libgcj --enabl
e-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enab
le-concept-checks --enable-version-specific-runtime-libs --build=mingw32 --with-
bugurl=http://www.mingw.org/bugs.shtml --prefix=/mingw --with-gmp=/mingw/src/gcc
/gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-mpfr-root --with-libiconv-prefix=/
mingw/src/gcc/libiconv-root
Thread model: win32
gcc version 4.3.0 20080305 (alpha-testing) mingw-20080502 (GCC)
COMPILER_PATH=c:/documents and settings/dan/my 
documents/programs/cygwin/home/da
n/ming/bin/../libexec/gcc/mingw32/4.3.0/;c:/documents and settings/dan/my 
docume
nts/programs/cygwin/home/dan/ming/bin/../libexec/gcc/;c:/documents and 
settings/
dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../.
/../../mingw32/bin/
LIBRARY_PATH=c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan
/ming/bin/../lib/gcc/mingw32/4.3.0/;c:/documents and settings/dan/my 
documents/p
rograms/cygwin/home/dan/ming/bin/../lib/gcc/;c:/documents and 
settings/dan/my do
cuments/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../../../m
ingw32/lib/;c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/
ming/bin/../lib/gcc/mingw32/4.3.0/../../../
COLLECT_GCC_OPTIONS='-shared' '-v' '-o' 'outputdll.dll' '-mtune=i386'
 c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/..
/libexec/gcc/mingw32/4.3.0/collect2.exe --shared -Bdynamic -e 
_DllMainCRTStartup
@12 --enable-auto-image-base -o outputdll.dll c:/documents and 
settings/dan/my d
ocuments/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../../dll
crt2.o c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/
bin/../lib/gcc/mingw32/4.3.0/crtbegin.o -Lc:/documents and settings/dan/my 
docum
ents/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0 -Lc:/documents 
a
nd settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/gcc -Lc:/d
ocuments and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/../lib/
gcc/mingw32/4.3.0/../../../../mingw32/lib -Lc:/documents and settings/dan/my 
doc
uments/programs/cygwin/home/dan/ming/bin/../lib/gcc/mingw32/4.3.0/../../.. 
dllte
st.o -lgcj -lws2_32 -lstdc++ -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luse
r32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcr
t c:/documents and settings/dan/my 
documents/programs/cygwin/home/dan/ming/bin/.
/lib/gcc/mingw32/4.3.0/crtend.o

----- Original Message ----- 
From: "Andrew Haley" <aph@redhat.com>
To: "Daniel Walter" <d2walter@hotmail.com>
Cc: <java@gcc.gnu.org>
Sent: Tuesday, December 16, 2008 5:39 AM
Subject: Re: creating shared dlls yields undefined reference to `WinMain@16' 
in mingw 4.3


> Daniel Walter wrote:
>> Whenever I add an object file that was generated with gcj to a g++ link
>> command for a shared dll, I get an undefined reference to `WinMain@16'.
>> This seems to indicate that for some reason gcc wants to build an
>> executable instead of a shared library.  This was working in gcc 3.4 -
>> though I was using cygwin with gcj -mno-cygwin which is no longer
>> supported.
>>
>> Is building dlls with g++ and gcj supported in newer versions of gcc?
>> Is there a different link command that will not try to build an 
>> executable?
>>
>>
>> works> g++ -shared cpptest.o -o pdflib.dll
>>
>> works - event with lgcj> g++ -shared cpptest.o -lgcj -lws2_32 -o 
>> pdflib.dll
>>
>> fails - it tries to build an executable> g++ -shared javatest.o 
>> cpptest.o -lgcj -lws2_32 -o pdflib.dll
>
> More information needed.  'g++ -v' will show you what is being linked.
> There is presumably a way to ask what symbols are needed by the various
> libraries that you're linking, so have a look which one needs 
> `WinMain@16'.
>
> Andrew.
> 



More information about the Java mailing list