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 Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Wed, 3 Mar 2004 15:52:00 -0500 (EST) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: "G.-B. Hauck" cc: cygwin AT cygwin DOT com Subject: Re: WinMain in an own static lib -> _WinMain AT 16 undefined reference ?! ;.( In-Reply-To: <1078340535.4312.9.camel@haux.local> Message-ID: References: <1078340535 DOT 4312 DOT 9 DOT camel AT haux DOT local> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.39 On Wed, 3 Mar 2004, G.-B. Hauck wrote: > Hi Gurus ! > > I have a problem with cygwin gcc (gcc version 3.3.1 cygwin-special) - i > think that i just don't understand "ld" - so maybe someone can help me > .... > > For my "Application-Framework" i need to put WinMain(...) in a lib - but > it doesnt work - please take a look on a minimalistic example: > > > /* winmain.cc */ > #include > extern "C" void NewEntry(); > extern "C" int APIENTRY WinMain(HINSTANCE hI,HINSTANCE hPI, > LPSTR lpCmdLine,int nCmdShow) > { > NewEntry(); > return 0; > } > > > /* test.cc */ > #include > extern "C" void NewEntry() > { > MessageBox(NULL,"test","test",MB_OK); > } > > ------------ > making test.exe with: > g++ -c winmain.cc > g++ -c test.cc > g++ -mwindows -mno-cygwin -o test.exe winmain.o test.o > > is ok -> running test.exe gives you a wonderfull MessageBox ... > > > BUT: > g++ -c winmain.cc > g++ -c test.cc > ar -rs libmaintest.a winmain.o > g++ -mwindows -mno-cygwin -o test.exe test.o -L./ -lmaintest > > /usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../i686-pc-mingw32/lib/libmingw32.a(main.o)(.text+0x9b):main.c: undefined reference to `_WinMain AT 16' > collect2: ld returned 1 exit status > > Why ld can't find _WinMain AT 16 - nm -g libmaintest.a gives: > winmain.o: > U _NewEntry > 00000000 T _WinMain AT 16 > > Calling the linker with my lib "before" test.o, i.e. > g++ -mwindows -mno-cygwin -o test.exe -L./ -lmaintest test.o > gives the same ... > > I'm hanging around for two days with this ;-( > > TIA and Thank You, Spasibo, Danke, Merci .... > Georg Georg, The way ld works is that all the symbols in object files get included unconditionally, whereas only the undefined symbols from the libraries get included. Also, ld searches forward for undefined symbols. To resolve _WinMain AT 16 with a symbol from your library, it needs to come *after* the library that needs it (/usr/i686-pc-mingw32/lib/libmingw32.a). Unfortunately (for you), gcc/g++ puts all the default libraries *last* when it calls ld. You need to override that order. IOW, I succeeded in linking your app using the following command: g++ -mwindows -mno-cygwin -o test.exe test.o -lmingw32 -L./ -lmaintest You are welcome, pozhalujsta, es ist nichts[*], je vous en prie. Igor [*] this one's automatically translated, sorry. :-) -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "I have since come to realize that being between your mentor and his route to the bathroom is a major career booster." -- Patrick Naughton -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/