Compling a module without a main

This is a discussion on Compling a module without a main within the C Programming forums, part of the General Programming Boards category; I have a module pgm that contains only definitions and functions. I have not included a main() statement. The module ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    32

    Compling a module without a main

    I have a module pgm that contains only definitions and functions. I have not included a main() statement.

    The module does have an associated header file.

    When I compile the module I am getting errors as attached:


    usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start':
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    make: *** [mod.o] Error 1

    These are not preventing my other programmes from compiling or running.

    However, I also have a makefile that is to compile the "group" of programmes - and if I try "make all" - the compiler is displaying this error and then stopping.

    Do I need a main method in my module? (I have tried to put one in, but get errors "multiple definition of main"


    If not - is there a flag I should use to compile the module that will eliminate the error.
    Thanks
    Sue

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    49
    compile it like this:
    gcc -c -o YourProg.o YourProg.c
    Hello, everyone.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    You compile all of your source files using the -c option.

    In any event, ONE (and only one) of your source files must contain a main()

    You then "compile" all your objects like so
    gcc -o prog main.o functions.o menu.o

    Just tell the compiler the list of previously created .o files. The compiler will know what to do with them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused as to how to pass back to main
    By J-Camz in forum C Programming
    Replies: 6
    Last Post: 11-28-2008, 07:21 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Return Statement
    By Daveo in forum C Programming
    Replies: 21
    Last Post: 11-09-2004, 05:14 AM
  4. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 04:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21