linking error..

This is a discussion on linking error.. within the C++ Programming forums, part of the General Programming Boards category; i kno this is a really general "?" but im gettin this error: Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    19

    Question linking error..

    i kno this is a really general "?" but im gettin this error:

    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/project.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    project.exe - 2 error(s), 0 warning(s)

    i have a source file and two header files im trying to link to build the file. the header files are utilizing templates and are being used as a linked list.

    can anyone list me some possibilites as to why im gettin this error??

    RAZ

  2. #2
    Registered User alex6852's Avatar
    Join Date
    Sep 2001
    Posts
    43
    What compiler are you using?
    C++ rulez!!!

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    VC++

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    My guess is you have a winMain and not main.

    If you're compiling a windows GUI app, you have a winMain, and you should be compiling the project as a GUI app.

    If you're compiling a console app, then you have a main.

    Basically, decide which type of project you're building, and make your 'main' consistent with that
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    hmm... well ive been compiling a console app..
    but to tell u the truth.. i dont kno the difference between a winMain and a main.

    i 'think' im using a main but im not sure..

    what makes it a winMain and what constitutes a regular main?

    RAZ

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    > i 'think' im using a main but im not sure..
    If you are, then you didn't include that source file in the project, otherwise the linker would have found it.

    And main is different from Main (for example)

    > what makes it a winMain and what constitutes a regular main?
    GUI program or console program
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    hmm..

    well i'm compiling a console app, and i incuded the source file.. but i'm still gettin the error.

    any ideas?

    RAZ

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    19

    Unhappy here ya go.

    //listnd.h

    #ifndef LISTND_H
    #define LISTND_H

    template< class NODETYPE > class IndexedList;

    template<class NODETYPE>
    class ListNode {
    friend class IndexedList< NODETYPE>;
    public:
    ListNode(const NODETYPE&);
    NODETYPE getData() const;
    private:
    NODETYPE data;
    ListNode<NODETYPE> *nextPtr;
    };

    template<class NODETYPE>
    ListNode<NODETYPE>::ListNode(const NODETYPE &info)
    :data(info),nextPtr(0){}

    template< class NODETYPE>
    NODETYPE ListNode<NODETYPE>::getData() const { return data;}

    #endif

    /************************************************/

    //IndexedList.h

    #ifndef INDEXEDLIST_H
    #define INDEXEDLIST_H

    #include <iostream>
    #include <cassert>
    #include "listnd.h"

    using std::cout;

    template<class NODETYPE>
    class IndexedList{
    public:
    IndexedList();
    ~IndexedList();
    void insertAtFront( const NODETYPE &);
    void insertAtBack( const NODETYPE &);
    bool removeFromFront( NODETYPE &);
    bool removeFromBack( NODETYPE &);
    bool deleteFromIndexedList(NODETYPE &);
    bool searchIndexedList(NODETYPE &);
    bool isEmpty() const;
    void print() const;
    private:
    ListNode<NODETYPE> *firstPtr;
    ListNode<NODETYPE> *lastPtr;

    ListNode<NODETYPE> *getNewNode(const NODETYPE &);
    };

    template<class NODETYPE>
    IndexedList<NODETYPE>::IndexedList():firstPtr(0),l astPtr(0){}

    template<class NODETYPE>
    IndexedList<NODETYPE>::~IndexedList()
    {
    if(!isEmpty()){
    cout<<"Destroying nodes...\n";

    ListNode<NODETYPE> *currentPtr=firstPtr, *tempPtr;

    while(currentPtr != 0){
    tempPtr = currentPtr;
    cout<<tempPtr->data<<'\n';
    currentPtr = currentPtr->nextPtr;
    delete tempPtr;
    }
    }
    cout<<"All nodes destroyed\n\n";
    }

    template<class NODETYPE>
    void IndexedList<NODETYPE>::insertAtFront(const NODETYPE &value)
    {
    ListNode<NODETYPE> *newPtr = getNewNode(value);

    if (isEmpty())
    firstPtr = lastPtr = newPtr;
    else{
    newPtr->nextPtr = firstPtr;
    firstPtr = newPtr;
    }
    }

    template<class NODETYPE>
    void IndexedList<NODETYPE>::insertAtBack( const NODETYPE &value)
    {
    ListNode<NODETYPE> *newPtr = getNewNode(value);

    if(isEmpty())
    firstPtr = lastPtr = newPtr;
    else {
    lastPtr->nextPtr = newPtr;
    lastPtr = newPtr;
    }
    }

    template<class NODETYPE>
    bool IndexedList<NODETYPE>::removeFromFront(NODETYPE &value)
    {
    if (isEmpty())
    return return;
    else {
    ListNode<NODETYPE> *tempPtr = firstPtr;

    if(firstPtr ==lastPtr)
    firstPtr = lastPtr = 0;
    else
    firstPtr = first->nextPtr;

    value = tempPtr->data;
    delete tempPtr;
    return return;
    }
    }

    template<class NODETYPE>
    bool IndexedList<NODETYPE>::removeFromBack(NODETYPE &value)
    {
    if(isEmpty())
    return return;
    else{
    ListNode<NODETYPE> *tempPtr = lastPtr;

    if(firstPtr == lastPtr)
    firstPtr = lastPtr = 0;
    else {
    ListNode<NODETYPE> *currentPtr = firstPtr;

    while(currentPtr->nextPtr!=lastPtr)
    currentPtr = currentPtr->nextPtr;

    lastPtr = currentPtr;
    currentPtr->nextPtr = 0;
    }

    value = tempPtr->data;
    delete tempPtr;
    return return;
    }
    }

    template <class NODETYPE>
    bool IndexedList<NODETYPE>::isEmpty() const
    {return firstPtr ==0;}

    template <class NODETYPE>
    ListNode<NODETYPE> *IndexedList<NODETYPE>::getNewNode( const NODETYPE &value)
    {
    ListNode<NODETYPE> *ptr =
    new ListNode<NODETYPE>(value);
    //assert(ptr!=0);
    return ptr;
    }

    template <class NODETYPE>
    void IndexedList<NODETYPE>:rint()const
    {
    if(isEmpty()){
    cout<<"The list is empty\n\n";
    return;
    }

    ListNode<NODETYPE> *currentPtr = firstPtr;

    cout<<"The list is: ";

    while (currentPtr != 0){
    cout<<currentPtr->data<<' ';
    currentPtr = currentPtr->nextPtr;
    }

    cout<<"\n\n";
    }

    template<class NODETYPE>
    bool IndexedList<NODETYPE>::deleteFromIndexedList(NODET YPE &value)
    {
    return true; //code not filled in yet

    }

    template<class NODETYPE>
    bool IndexedList<NODETYPE>::searchIndexedList(NODETYPE &value)
    {
    return true; //code not filled in yet
    }

    #endif
    /*************************************************/
    //project.cpp

    #include <iostream>
    #include <stdlib.h>
    #include <cassert>

    using namespace std;

    #include "IndexedList.h"

    #define STOP "S"

    template<class NODETYPE>
    void testIndexedList(IndexedList<NODETYPE> &list)
    {
    char ch;
    CName name;

    do {
    cout << "Select the operation you want (A - add, D - delete, F - search, Q - quit):";
    cin.get();
    switch(tolower(cin.get())) {
    case 'a':
    cout << "Enter the name to be inserted:";
    cin >> list;
    break;
    case 'd':
    cout << "Enter the name to be deleted:";
    cin >> name;
    if (list.deleteFromIndexedList(name))
    cout << name << " is deleted.\n";
    else
    cout << name << " cannot be found.\n";
    break;
    case 'f':
    cout << "Enter the name to be looked for:";
    cin >> name;
    if(list.searchIndexedList(name))
    cout << name << " exists in the list.\n";
    else
    cout << name << " cannot be found.\n";
    break;
    case 'q':
    return;
    default:
    break;
    }
    cout << "Continue? (Y/N):";
    cin.get();
    ch = tolower(cin.get());
    } while (ch == 'y');
    }

    template<class NODETYPE>
    int main()
    {
    IndexedList list1, list2;
    string s;

    cout << "Please enter the first list:" << endl;
    cin >> s;
    while (s != STOP) {
    for(int i = s.length() ; i >0; i--) cin.putback(s.at(i-1));
    cin >> list1;
    cin >> s;
    }

    cout << "Please enter the second list:" << endl;
    cin >> s;
    while (s != STOP) {
    for(int i = s.length() ; i >0; i--) cin.putback(s.at(i-1));
    cin >> list2;
    cin >> s;
    }

    cout << "The first list is:\n";
    cout << "==============================\n";
    cout << list1;
    cout << "==============================\n\n";
    cout << "The second list is:\n";
    cout << "==============================\n";
    cout << list2;
    cout << "==============================\n\n";

    list1 += list2;
    cout << "The 3rd list is:\n";
    cout << "==============================\n";
    cout << list1;
    cout << "==============================\n\n";
    testIndexedList(list1);
    cout << "The 3rd list is:\n";
    cout << "==============================\n";
    cout << list1;
    cout << "==============================\n\n";

    return 0;
    }




    // and thanks again if u get a chance to look at this

    //RAZ

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    make sure in your project options it says subsystem:console and not subsystem:windows
    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

  10. #10
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I'm not sure why you've done it, but main() can't be a template function. You'll have to remove template<class NODETYPE> before int main().
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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