delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/28/14:24:44

From: fredex AT fcshome DOT stoneham DOT ma DOT us
Message-Id: <199605281807.OAA08449@fcshome.stoneham.ma.us>
Subject: Re: Linking problem
To: jlhawk AT interaccess DOT com (Jeff Hawk)
Date: Tue, 28 May 1996 14:07:35 -0400 (EDT)
Cc: djgpp AT delorie DOT com
In-Reply-To: <31AA02D7.F99@interaccess.com> from "Jeff Hawk" at May 27, 96 02:30:31 pm

Thinking furiously, Jeff Hawk wrote:
> 
> When I try to compile this:
> 
>     #include <stdio.h>
> 
>     void main(void)
>     {
>         printf("Hello\n");
>     }
> 
> I get this:
> 
>     _main.c(.text+0x1a): undefined reference to `djgpp_last_ctor'
>     _main.c(.text+0x1f): undefined reference to `djgpp_first_ctor'
>     _main.c(.text+0x2f): undefined reference to `djgpp_first_ctor'
>     exit.c(.text+0x29): undefined reference to `djgpp_last_dtor'
>     exit.c(.text+0x2e): undefined reference to `djgpp_first_dtor'
>     exit.c(.text+0x3f): undefined reference to `djgpp_first_dtor'
> 
> Any idea why?

Yes. Though I'm not, at the moment, where I can try it on djgpp, I
think I can eyeball a fair guess.

main() is prototyped incorrectly. main() is NOT a void function (See
the ANSI/ISO standard for the C language).

The correct prototype for main is:

	int main (int, char **);

My guess is that the incorrect prototype is fouling up something in the
compiler, which then confuses the linker. Try writing your program like
this (below) and see if it works better:

#include <stdio.h>

int main(int argc, char ** argv)
{
 printf("Hello\n");
}

[EDITORIAL-MODE-ON]
Treating main() as if it were a void function is a bad habit which is
discussed (complete with flamage) almost weekly in comp.lang.c. It seems
to be perpetrated by ill-informed high-school and/or college instructors,
but even more so it is perpetrated by ill-informed authors of poorly
written books, one of the most notable culprits being Herbert Schildt.
[EDITORIAL-MODE-OFF]

Fred
-- 
-------------------------------------------------------------------------------
 .----    Fred Smith    /                        Office: fred AT computrition DOT com 
( /__  ,__.   __   __ /  __   : /                                 508-663-2524 
 /    /  /   /__) /  /  /__) .+'           Home: fredex AT fcshome DOT stoneham DOT ma DOT us 
/    /  (__ (___ (__(_ (___ / :__                                 617-438-5471 
-------------------------------- Jude 1:24,25 ---------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019