Odd Behaviour:compiling with no `main` function: Suse 7.3 Prof
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. I've googled the problem but seemed to get loads of results with people posting a similar problem (but no clear solution) I am using: Kernel: Linux linux 2.4.10-4GB #1 Fri Sep 28 17:20:21 GMT 2001 i686 unknown gcc:gcc version 2.95.3 20010315 (SuSE) I guess the solution would be to go through a series of upgrades (gcc, lib, kernel), but would be grateful for a `pointer` in the right direction. Many thanks, James ____________________________________________________________ Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
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/
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
participants (3)
-
Anders Johansson
-
J Can
-
Nick LeRoy