Why am I getting this linker error?

This is a discussion on Why am I getting this linker error? within the C++ Programming forums, part of the General Programming Boards category; I don't understand why I'm getting this error: g++ -o tht testhashtable.o /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 ...

  1. #1
    Unregistered
    Guest

    Why am I getting this linker error?

    I don't understand why I'm getting this error:

    g++ -o tht testhashtable.o
    /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

    Compilation exited abnormally with code 1 at Mon Dec 3 14:15:07

    when I try to link the object file created by this code:

    #include <iostream>
    #include <fstream>
    //using namespace std;
    #include <stdlib.h>
    #include "HashTable.h"
    #include "HashableString.h"

    #ifdef TEST_HASHTABLE

    void main(void)//int argc, char *argv[])
    {
    HashTable<HashableString> ht(3);

    string str;
    char in[256];

    while(true)
    {

    cout << "Enter Command : ";
    gets(in);
    str = in;

    if(str == "q" || str == "")
    {
    cout << "Execution complete" << endl;
    break;
    }

    if(str[0] == 'i')
    {
    string tmp = str.substr(2, str.length()-2);
    HashableString htmp = tmp;

    ht.search_and_insert(htmp);
    }

    if(str[0] == 's')
    {
    string tmp = str.substr(2, str.length()-2);
    HashableString htmp = tmp;

    if(ht.search(htmp))
    {
    cout << "Found in table " << endl;
    }
    else
    {
    cout << "Not found " << endl;
    }
    }

    ht.debug_print();

    }

    return EXIT_SUCCESS;
    }

    #endif

    Any help is much appreciated. TIA.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    for a start try int main and not void main. void main is illegal and a good compiler will disallow it.
    also gets() is nasty. fgets() from stdin is much safer.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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