1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

compilation error : undefined reference to 'main'

Discussion in 'C' started by manoj1987, Sep 4, 2009.

  1. manoj1987

    manoj1987 New Member

    Joined:
    Apr 23, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Chennai
    Home Page:
    Hi !
    I have been learning C back from basics. Recently i tried out a simple program myHello.c , which contained the following code :


    1. //myHello.c
    2. #include"hello.h"
    3. int main(void)
    4. {
    5. hello("WORLD");
    6. return 0;
    7. }
    next, i created hello.h that contained the following code :

    1. //hello.h
    2. void hello(const char* name);
    Finally i created helloFunc.c that contained the declaration for hello() :

    1. //helloFunc.c
    2. #include<stdio.h>
    3. #include"hello.h"
    4. void hello(const char* name)
    5. {
    6. printf("hello, %s \n",name);
    7. }
    I compiled the C sources as follow :
    gcc -Wall myHello.c helloFunc.c -o newHello

    I received the following error :
    /usr/lib/gcc/i486-linux-gnu-4.3.3/../../../../libcrt1.o: In function '_start' :

    /build/buildd/libc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to 'main'


    collect2: ld returned 1 exit status

    i tried googling , but couldnt get a satisfying solution ! please help !

    <Manoj>
     
  2. prasad1990

    prasad1990 New Member

    Joined:
    Jul 9, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    karnataka
    hey try removing 'void' from main............
     
  3. manoj1987

    manoj1987 New Member

    Joined:
    Apr 23, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Chennai
    Home Page:
    Hi !
    I tried a different solution :

    just use a Makefile.
    You need to build them using:

    gcc -c helloFunc.c -o helloFunc.o
    gcc -c myHello.c -o myHello.o
    gcc myHello.o helloFunc.o -o hello

    Let me also try the solution you suggested . Thanks :)
     

Share This Page