From: Tatsh <dd...@gm...> - 2010-05-11 14:34:35
|
Mark Allyn wrote: > Hi Keith and Greg - > > Yes, I know that the sensible thing to do is to simply do gcc proggy.o -o > proggy.exe. But, I am one of those silly people who enjoy doing things > the hard way so that I learn new stuff. If you are curious, `man ld`. It has everything you could need to know. > > I really would like to know what the runtime start up code is. I used the > -v option in the "standard" gcc -g proggy.c command but the output is very > difficult to read. > > You don't want to squelch curiousity do you? Even old geezers like me > should have the opportunity to learn new things, wouldn't you think? It > seems to me that the only damage I'm doing is wasting some of my own time > and a couple billion or so electrons...if you decide to not waste your own > time replying. > > Anyway, thanks, and regards as well, > > Mark > > > ----- Original Message ----- > From: "Keith Marshall" <kei...@us...> > To: <min...@li...> > Sent: Monday, May 10, 2010 5:26 PM > Subject: Re: [Mingw-users] how to use ld.exe > > > On Monday 10 May 2010 22:05:30 Mark Allyn wrote: > >> Please forgive a newbie question regarding ld usage. > >> I thought for fun I would compile a c program using: > >> > >> gcc -c -g proggy.c -o proggy.o > > > > So far, so good. > > > >> And I did. I got proggy.o > > > > As we would expect. > > > >> Then I decided to do a link like this: > >> > >> ld -L/c/mingw/lib proggy.o -lmsvcrt > > > > Now you are just trying to be too clever for your own good; the more > > so since you claim to be a newbie, you should not even think about > > invoking ld directly -- you should use gcc to link, like this: > > > > gcc -o proggy.exe proggy.o > > > > and leave gcc to pass the proper flags and prerequisite system object > > modules and libraries. > > > >> But, I get back a message indicating that: > >> _main and __alloca are undefined references. Other crt symbols > >> like pow() and printf() resolved just fine. > > > > Those which are unresolved would be provided by the runtime start-up > > code, which you've not asked ld to include in the link. > > > >> If I go back to the c code and change main into _main, and > >> recompile, the linker works just fine. > > > > Now you've substituted your own _main for the proper start-up code, > > (which would ultimately call your main); your application almost > > certainly will not initialise correctly. > > > >> So....what is going on here? What do I have to put into the ld > >> command line to get the linker to understand that my "main" symbol > >> is OK? Do I have to set an option in the initial GCC command, or > >> do I have to put a library into the LD step? > > > > Neither; just use GCC to link, as is intended. > > > > > > ------------------------------------------------------------------------- > >----- > > > > _______________________________________________ > > MinGW-users mailing list > > Min...@li... > > > > This list observes the Etiquette found at > > http://www.mingw.org/Mailing_Lists. > > We ask that you be polite and do the same. Disregard for the list > > etiquette may cause your account to be moderated. > > > > _______________________________________________ > > You may change your MinGW Account Options or unsubscribe at: > > https://lists.sourceforge.net/lists/listinfo/mingw-users > > --------------------------------------------------------------------------- > --- > > _______________________________________________ > MinGW-users mailing list > Min...@li... > > This list observes the Etiquette found at > http://www.mingw.org/Mailing_Lists. > We ask that you be polite and do the same. Disregard for the list > etiquette may cause your account to be moderated. > > _______________________________________________ > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > -- Tatsh www.tatsh.net dd...@gm... |