[prev in list] [next in list] [prev in thread] [next in thread] 

List:       suse-linux-e
Subject:    Re: [SLE] Odd Behaviour:compiling with no `main` function: Suse 7.3 Prof
From:       Nick LeRoy <nleroy () cs ! wisc ! edu>
Date:       2004-05-27 21:32:35
Message-ID: 200405271632.35848.nleroy () cs ! wisc ! edu
[Download RAW message or body]

On Thu May 27 2004 4:16 pm, J Can wrote:
> Hi Susers,

Hello,

> 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 isn't a problem, and is exactly what should happen.  If you're just 
trying to compile this into an object file that you can just link with 
another, then you want to pass the "-c" flag:

$ gcc -o checkpass.o checkpass.c

You can then link it with an object file that _does_ define main:

$ gcc -o program main.o checkpass.o

This is pretty much the way that C is defined.  Basically, main() defines the 
entry point for your program, and you'll need to provide one somewhere....

You can override this behavior by playing with the libc startup files and 
such, but, unless you know what you're doing, you don't want to go down that 
road.

BTW, what are you trying to do?  That may help direct you in the right 
direction.

-Nick

-- 
           <<< Knock, knock, Neo. >>>
 /`-_    Nicholas R. LeRoy               The Condor Project
{     }/ http://www.cs.wisc.edu/~nleroy  http://www.cs.wisc.edu/condor
 \    /  nleroy@cs.wisc.edu              The University of Wisconsin
 |_*_|   608-265-5761                    Department of Computer Sciences

-- 
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-help@suse.com
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-faq@suse.com


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic