public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* creating shared dlls yields undefined reference to `WinMain@16' in mingw 4.3
@ 2008-12-16  5:54 Daniel Walter
  2008-12-16 10:39 ` Andrew Haley
  0 siblings, 1 reply; 17+ messages in thread
From: Daniel Walter @ 2008-12-16  5:54 UTC (permalink / raw)
  To: java

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

Daniel

BTW, thank you for the help with the C++ references for garabage collection. 
Exactly how this works is still a little fuzzy, but at least I know what I 
can do to make things work.


gcc -v
Using built-in specs.
Reading specs from c:/documents and settings/dan/my 
documents/programs/cygwin/ho
me/dan/ming/bin/../lib/gcc/mingw32/4.3.0/libgcj.spec
rename spec startfile to startfileorig
rename spec lib to liborig
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) 

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: creating shared dlls yields undefined reference to `WinMain@16' in mingw 4.3
@ 2008-12-17  7:47 Danny Smith
  2008-12-17 10:35 ` Andrew Haley
  0 siblings, 1 reply; 17+ messages in thread
From: Danny Smith @ 2008-12-17  7:47 UTC (permalink / raw)
  To: d2walter; +Cc: java

Sorry for joining this thread sideways and lately
At:    http://gcc.gnu.org/ml/java/2008-12/msg00032.html

Andrew Haley wrote:
>"So, which object file in libmingw.a contains the undefined reference to
> `WinMain@16'  And what dependency is causing it to be pulled in?"

On i386 targets libgcj has a undefined reference to 'main' due to the
fallback backtrace code introduced with this patch:

2006-07-14  Ranjit Mathew  <rmathew@gcc.gnu.org>

	* stacktrace.cc (_Jv_StackTrace::GetStackTrace): Unconditionally use
	_Unwind_Backtrace().
	(_Jv_StackTrace::GetCallerInfo): Enable even for targets using SJLJ
	EH.
	(_Jv_StackTrace::GetClassContext): Unconditionally use
	_Unwind_Backtrace().
	(_Jv_StackTrace::GetFirstNonSystemClassLoader): Likewise.
	* sysdep/i386/backtrace.h (HAVE_FALLBACK_BACKTRACE): Do not define.
	(_Unwind_GetIPInfo): Define macro if SJLJ EH is in use.
	(_Unwind_GetRegionStart): Likewise.
	(_Unwind_Backtrace): Likewise.
>>>>>	(fallback_backtrace): Accept additional unwind trace function
>>>>>	argument.  Call it during unwinding.  Stop when any of _Jv_RunMain(),
>>>>>	_Jv_ThreadStart() or main() is seen during unwinding.
	* sysdep/generic/backtrace.h (fallback_backtrace): Accept an
	additional unwind trace function argument.


This code. and reference to 'main' gets pulled into the users dll from
a static libgcj.a
Since windows dll's (unlike ELF shared objects) do not allow undefined
symbols, the reference to 'main' must be resolved in the dll.

In the event, it is resolved by mingw runtime's main.c, which just
calls WinMain (an
alternative 'main' for Windows GUI apps in MSVC land).  I won't go
into detail's but
this main.c in libmingw.a is an old hack for the benefit of MSVC-based code.

A dummy main() in the dll is one workaround,  but you need to be
careful not to export it.

Danny

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: creating shared dlls yields undefined reference to `WinMain@16' in mingw 4.3
@ 2008-12-18  4:12 Daniel Walter
  2008-12-18 10:17 ` Andrew Haley
  0 siblings, 1 reply; 17+ messages in thread
From: Daniel Walter @ 2008-12-18  4:12 UTC (permalink / raw)
  To: Daniel Walter, Andrew Haley; +Cc: Danny Smith, java

Thank you for all the help on this. For anyone who is searching the archives 
for MinGW gcj information, I will summarize.

1. If you are trying to build a dll in MinGW, you may need to make a dummy 
WinMain function. This should not be exported outside of the dll. This will 
get you past the libgcj reference to main/WinMain for backtraces.

2. When statically linking with libgcj 
use -Wl,--whole-archive -lgcj -Wl,--no-whole-archive. Adding this forces the 
linker to link all of libgcj instead of just the parts that are referenced 
by your program. This is important because some parts of libgcj are loaded 
via reflexion rather than directly through symbolic references. Your program 
will start fine and crash later without this.

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

end of thread, other threads:[~2008-12-19 20:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-16  5:54 creating shared dlls yields undefined reference to `WinMain@16' in mingw 4.3 Daniel Walter
2008-12-16 10:39 ` Andrew Haley
2008-12-16 16:31   ` Daniel Walter
2008-12-16 17:30     ` Andrew Haley
2008-12-16 20:11       ` Daniel Walter
2008-12-16 20:26         ` Andrew Haley
2008-12-16 20:55           ` Daniel Walter
2008-12-17  7:47 Danny Smith
2008-12-17 10:35 ` Andrew Haley
2008-12-17 18:45   ` Daniel Walter
2008-12-17 18:56     ` Andrew Haley
2008-12-18  4:12 Daniel Walter
2008-12-18 10:17 ` Andrew Haley
2008-12-18 11:42   ` BGB
2008-12-18 17:03   ` Daniel Walter
2008-12-19  5:44     ` BGB
     [not found]       ` <BLU138-DAV5CF88D886B9DC7B21FB2F80F00@phx.gbl>
2008-12-19 20:07         ` BGB

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