Mailinglist Archive: opensuse (4547 mails)

< Previous Next >
Re: [SLE] Odd Behaviour:compiling with no `main` function: Suse 7.3 Prof
  • From: Anders Johansson <andjoh@xxxxxxxxxx>
  • Date: Thu, 27 May 2004 23:25:01 +0200
  • Message-id: <200405272325.01799.andjoh@xxxxxxxxxx>
On Thursday 27 May 2004 23.16, J Can wrote:
> Hi Susers,
>
> Odd results when trying to complie a C program with no
> 'main' function.
>
> I compile a simple C program with no main function
> like so:
>
> james@linux:~/usp> gcc -o checkpass checkpass.c
> /usr/lib/crt1.o: In function `_start':
> /usr/lib/crt1.o(.text+0x18): undefined reference to
> `main'
> collect2: ld returned 1 exit status
>
> The odd thing is programs with main defined are ok.

This is odd? That's the way programs work. If you're compiling a program, you
need a main function, since that's what the OS calls to start your program.

If you want to compile something that doesn't have a main function, you need
to compile it as a library. I suggest you take a look at the library HOWTO

http://www.tldp.org/HOWTO/Program-Library-HOWTO/

< Previous Next >
References