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 Date: Fri, 26 Nov 2004 00:09:33 -0500 (EST) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Niklas Odenteg cc: cygwin AT cygwin DOT com Subject: RE: linking problems using gcc In-Reply-To: <000f01c4d333$93049380$0602a8c0@malenkov> Message-ID: References: <000f01c4d333$93049380$0602a8c0 AT malenkov> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.39 Niklas, First off, . Hint for Outlook users: Google for "PCYMTNQREAIYR Outlook". Thanks. Secondly, you did not provide a minimal example that demonstrates the problem. Your statement makes no sense -- Cygwin does define (and use) both rand() and srand() (see lines 104 and 109 of /usr/include/stdlib.h). FWIW, so does MinGW (what you get when you pass a -mno-cygwin flag to gcc -- see lines 348-349 of /usr/include/mingw/stdlib.h). Note that both Cygwin and MinGW headers declare rand() and srand() as __cdecl, so that not including the appropriate header *will* hurt you during the link phase. Again, instead of trying to work around a problem that doesn't exist, and calling the platform stupid for no apparent reasons, why not try to actually add '#include ' to the start of your file, and see if that lets you use rand() and srand() normally? And if that doesn't work, please provide *the exact* command line that demonstrates the problem, and *the exact* error you get from the linker, so that we know what problem the approach below is trying to solve. HTH, Igor On Thu, 25 Nov 2004, Niklas Odenteg wrote: > Hi Igor! > > Thanks for trying to help. I'll solve it. The stupid platform (windows > or cygwin?) uses random and srandom instead of rand and srand! > Everything in order to confuse the enemy right ;-) > > I solved it with these small statements below. Little messy, but it > works. > > #ifndef MSDOS > #include > #else > #include > #define RAND > #endif > .... > #ifdef RAND > #define random rand > #define srandom(s) srand(s) > #endif > ... > #ifdef _LIBC > extern int srandom(); > extern int random(); > extern unsigned long time(); > #endif > > > Best > > /N > > > -----Original Message----- > From: Igor Pechtchanski [mailto:pechtcha AT XX DOT XXX DOT XXX] > Sent: den 25 november 2004 17:25 > To: Niklas Odenteg > Cc: cygwin AT XXXXXX DOT XXX > Subject: Re: linking problems using gcc > > On Thu, 25 Nov 2004, Niklas Odenteg wrote: > > > Hi! > > > > This may be a newbee Q, but I'll try anyway ;-) > > > > I trying to link a small C/C++ program and I got linking error on > > time(), rand() and srand(). These should be part of libc right? So way > > are they missing? Has cygwin some special libc implementation or > > something??? > > > > Confused programmer needs some help. > > Please post a small simple program that demonstrates the error, the > exact command line you used to compile it, and the exact error you get > from gcc. > > At a guess, you are missing some #includes, so the functions aren't > declared as 'extern "C"', and are name-mangled, so the linker doesn't > find them. -- 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! "The Sun will pass between the Earth and the Moon tonight for a total Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT -- 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/