Linker error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Linker error

  1. #1
    Join Date
    Feb 2009
    Posts
    48

    Linker error

    I am trying to compile a linked list implementation file that includes a linked list header file. I get this error.

    In function `_start':
    : undefined reference to `main'
    collect2: ld returned 1 exit status


    I know that since the implementation file is a cpp file without a main function, it needs some sort of special command when compiling, but I don't know what it is.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,089

    Re: Linker error

    You can compile, but you can't link without a main function.

  3. #3
    Join Date
    Feb 2009
    Posts
    48

    Re: Linker error

    Oh. My professor has shown in his lecture sample code in this same format with the class interface in a header file and the class implementation in a cpp file that includes the header file.

  4. #4
    Join Date
    Aug 2007
    Posts
    858

    Re: Linker error

    Quote Originally Posted by ichiben View Post
    Oh. My professor has shown in his lecture sample code in this same format with the class interface in a header file and the class implementation in a cpp file that includes the header file.
    In real world usage those files would be included in a larger project, which will have a main function somewhere else. Or, you could make them into a library instead of an executable program, you just have to change your linker settings.

  5. #5
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Linker error

    int main() is like an entry point to your's program.
    You can put the implementation file at main file but not recommended or include header file at main file.
    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center