-
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
-
What compiler are you using?
-
-
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
-
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
-
> 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
-
hmm..
well i'm compiling a console app, and i incuded the source file.. but i'm still gettin the error.
any ideas? :(
RAZ
-
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>::print()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
-
make sure in your project options it says subsystem:console and not subsystem:windows
-
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().