473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Unresolved External Help.

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::PrintData()// 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::PrintRoster(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
Jul 22 '05 #1
4 2926
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.

Jul 22 '05 #2
"Kyle Sheldon" <ks*****@ilstu.edu> 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
Jul 22 '05 #3
"Kyle Sheldon" <ks*****@ilstu.edu> wrote in message news:<bu**********@malachite.ilstu.edu>...
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::PrintData()// 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::PrintRoster(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
Jul 22 '05 #4
"Kyle Sheldon" <ks*****@ilstu.edu> wrote in message news:<bu**********@malachite.ilstu.edu>...
[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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rodolphe | last post by:
Hello, I'm French so sorry for my approximate English. When I try to compile a project under Visual C++ 6.0, I've got the following errors : applicap.obj : error LNK2001: unresolved external...
2
by: Freddy | last post by:
I am not an experienced programmer, but I had a VC++ program I am trying to eliminate all the VC++ commands from it...and keeping it as a normal C/C++ program......I guess I have succeeded so far,...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
5
by: cschettle | last post by:
I think you need to link with msvcrt.lib ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
6
by: sadegh | last post by:
Hi I have a problem with my program in VC++6 When I compile it, the following errors are listed. I spend a lot of time on the groups.google.com to find its reason, but none of comments could...
5
by: bonnielym84 | last post by:
Im new here..didnt noe whether is this the rite way to post my problem..Really need help here..i've been stucked in this error from last wk..My problem is like this..Im using VC++ 6.0 to compile my C...
0
by: bonnielym84 | last post by:
Im new here and im not sure whether is this the right place for me to post my question..anyway..hope that you can help me..i have been stucked in this problem since last wk..My problem is..I'm using...
0
by: Ryan Gaffuri | last post by:
hlink72@hotmail.com (Eric) wrote in message news:<ab8d8b14.0308220550.54fb5f22@posting.google.com>... LNK1120 is a standard C++ error. you using Visual C++? Means your references a class that...
2
by: =?Utf-8?B?YmFzaA==?= | last post by:
Hello, I am compiling a CPP code using Visual studion .net 2003. I get the following error, despite having windldap.h and wldap32.dll in my include and lib paths. Here is the error. uuid.lib...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.