Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Unresolved External Help.

Reply
Thread Tools

Unresolved External Help.

 
 
Kyle Sheldon
Guest
Posts: n/a
 
      01-16-2004
I'm currently working on a class "Course" and I'm getting an unresolved
external error when trying to compile.

I understand that unresolved externals are caused by declaration of methods
that are not defined, but I think I defined all my methods so this one has
got me stumped. Any help would be much appreciated.

Thank you for your time,

Kyle

course.h
--------
#ifndef COURSE_H
#define COURSE_H

#include <string>
using namespace std;

class Course
{
private:
string id;
int credithours;
string instructor;
string days;
string time;
string room;
int capacity;
string roster[50];
int size;
public:
Course();// Default Constructor
void ReadCourse(istream & fin);// Reads course information from file.
void WriteCourse(ostream & fout);// Writes course information to file.
void PrintData();// Prints's all data except roster to screen with labels.
void PrintRoster(ostream & out);// Prints Roster to any output stream.
void AddStudent(ostream & out, string newstudent);// Adds student to
roster.
};

#endif


Course.cpp
----------
#include "course.h"
#include <iostream>
using namespace std;

Course::Course()
{
id="0";
}

void Course::ReadCourse(istream & fin)// Reads course information from file.
{
fin >> id;
fin >> credithours;
getline(fin, instructor);
fin >> days;
getline(fin, time);
getline(fin, room);
fin >> capacity;
fin >> size;
for (int i=0; i<=size; i++)
{
getline(fin, roster[i]);
}
}

void Course::WriteCourse(ostream & fout)// Writes course information to
file.
{
fout << id << " " << credithours << "\n";
fout << instructor << "\n";
fout << days << " " << time << "\n";
fout << room << "\n";
fout << capacity << " " << size << "\n";
for (int i=0; i<=size; i++)
{
fout << roster[i] << "\n";
}
}

void Course:rintData()// Prints's all data except roster to screen with
labels.
{
cout << "Course ID: " << id << endl;
cout << "Credits: " << credithours << endl;
cout << "Instructor: " << instructor << endl;
cout << "Days and Time: " << days << " " << time << endl;
cout << "Capacity: " << capacity << endl;
cout << "Enrolled: " << size << endl;
}

void Course:rintRoster(ostream & out)// Prints Roster to any output
stream.
{
for (int i=0; i<=size; i++)
{
out << roster[i] << endl;
}
}

void Course::AddStudent(ostream & out, string newstudent)// Adds student to
roster.
{
size+=1;
roster[size]=newstudent;
}

ERROR:
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function _mainCRTStartup
Debug/Project 1.exe : fatal error LNK1120: 1 unresolved externals


 
Reply With Quote
 
 
 
 
Simon Saunders
Guest
Posts: n/a
 
      01-16-2004
On Fri, 16 Jan 2004 09:52:25 -0600, Kyle Sheldon wrote:

> I'm currently working on a class "Course" and I'm getting an unresolved
> external error when trying to compile.
>
> I understand that unresolved externals are caused by declaration of
> methods that are not defined, but I think I defined all my methods so
> this one has got me stumped. Any help would be much appreciated.
>
>


> ERROR:
> LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
> referenced in function _mainCRTStartup Debug/Project 1.exe : fatal error
> LNK1120: 1 unresolved externals


Every C++ program needs a "main" function, either written by you or
provided implicitly by some library. I guess you need to write one.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-16-2004
"Kyle Sheldon" <(E-Mail Removed)> wrote...
> I'm currently working on a class "Course" and I'm getting an unresolved
> external error when trying to compile.


Actually, you get this error when trying to _link_, not compile.

> I understand that unresolved externals are caused by declaration of

methods
> that are not defined, but I think I defined all my methods so this one has
> got me stumped. Any help would be much appreciated.
> [...]
>
> ERROR:
> LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
> referenced in function _mainCRTStartup
> Debug/Project 1.exe : fatal error LNK1120: 1 unresolved externals


Every C++ program has to contain a function called 'main'. Execution
starts with it. When you try to link your [incomplete] program, your
compiler is trying to resolve a reference to 'main'. Two solutions:
either stop trying to link an incomplete program, or add 'main' function.

Victor


 
Reply With Quote
 
JHenstay
Guest
Posts: n/a
 
      01-16-2004
"Kyle Sheldon" <(E-Mail Removed)> wrote in message news:<bu91cb$pv5$(E-Mail Removed)>...
> I'm currently working on a class "Course" and I'm getting an unresolved
> external error when trying to compile.
>
> I understand that unresolved externals are caused by declaration of methods
> that are not defined, but I think I defined all my methods so this one has
> got me stumped. Any help would be much appreciated.
>
> Thank you for your time,
>
> Kyle
>
> course.h
> --------
> #ifndef COURSE_H
> #define COURSE_H
>
> #include <string>
> using namespace std;
>
> class Course
> {
> private:
> string id;
> int credithours;
> string instructor;
> string days;
> string time;
> string room;
> int capacity;
> string roster[50];
> int size;
> public:
> Course();// Default Constructor
> void ReadCourse(istream & fin);// Reads course information from file.
> void WriteCourse(ostream & fout);// Writes course information to file.
> void PrintData();// Prints's all data except roster to screen with labels.
> void PrintRoster(ostream & out);// Prints Roster to any output stream.
> void AddStudent(ostream & out, string newstudent);// Adds student to
> roster.
> };
>
> #endif
>
>
> Course.cpp
> ----------
> #include "course.h"
> #include <iostream>
> using namespace std;
>
> Course::Course()
> {
> id="0";
> }
>
> void Course::ReadCourse(istream & fin)// Reads course information from file.
> {
> fin >> id;
> fin >> credithours;
> getline(fin, instructor);
> fin >> days;
> getline(fin, time);
> getline(fin, room);
> fin >> capacity;
> fin >> size;
> for (int i=0; i<=size; i++)
> {
> getline(fin, roster[i]);
> }
> }
>
> void Course::WriteCourse(ostream & fout)// Writes course information to
> file.
> {
> fout << id << " " << credithours << "\n";
> fout << instructor << "\n";
> fout << days << " " << time << "\n";
> fout << room << "\n";
> fout << capacity << " " << size << "\n";
> for (int i=0; i<=size; i++)
> {
> fout << roster[i] << "\n";
> }
> }
>
> void Course:rintData()// Prints's all data except roster to screen with
> labels.
> {
> cout << "Course ID: " << id << endl;
> cout << "Credits: " << credithours << endl;
> cout << "Instructor: " << instructor << endl;
> cout << "Days and Time: " << days << " " << time << endl;
> cout << "Capacity: " << capacity << endl;
> cout << "Enrolled: " << size << endl;
> }
>
> void Course:rintRoster(ostream & out)// Prints Roster to any output
> stream.
> {
> for (int i=0; i<=size; i++)
> {
> out << roster[i] << endl;
> }
> }
>
> void Course::AddStudent(ostream & out, string newstudent)// Adds student to
> roster.
> {
> size+=1;
> roster[size]=newstudent;
> }
>
> ERROR:
> LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
> referenced in function _mainCRTStartup
> Debug/Project 1.exe : fatal error LNK1120: 1 unresolved externals



It looks like the problem is your project actually is missing a "main"
function for running. The code above defines a Class, but a Class by
itself doesn't do much. You need a program which instantiates the
Class as an Object, then you would utilize the Methods declared above
on the Object:

int main (void)
{
.....
Course Mathmatics = new Course;
Mathmatics->PrintRoster(pStdOut);
.....
}

If you create a program with a main function and link it with the
compiled OBJect file of your Class, you should not get that linkage
error.

-JH
 
Reply With Quote
 
puppet_sock@hotmail.com
Guest
Posts: n/a
 
      01-16-2004
"Kyle Sheldon" <(E-Mail Removed)> wrote in message news:<bu91cb$pv5$(E-Mail Removed)>...
[snip]
> ERROR:
> LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
> referenced in function _mainCRTStartup
> Debug/Project 1.exe : fatal error LNK1120: 1 unresolved externals


Good thing you included the error message.

You've not defined the symbol main. Probably you are using one of
Microsoft's compilers and have screwed up the type of project so
as to have it want a main when you've provided it something like
WinMain, or the other way around. It's nothing to do with the
code, so you need help from a windows coding group to solve it.
Socks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM
Linking errors. - VC++ - Unresolved external Symbol mp C++ 2 12-12-2003 06:21 PM
"unresolved external symbol" error in MSVC++ 6.0 Rodolphe C++ 4 10-03-2003 09:44 AM
error LNK2001: unresolved external symbol _IID_IDirectDraw7 Izak Pretorius C++ 2 09-14-2003 11:18 AM
Re: unresolved external symbol error. Need help! John Harrison C++ 0 07-20-2003 07:18 PM



Advertisments