473,387 Members | 1,876 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,387 software developers and data experts.

unresolved external symbol

hello,

I use the Visual C++ 2005 Express Edition and I want to implement a
simple c++ programm which has a header file and a implementation file.

the header file:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. namespace main_savitch_2C
  4. {
  5. class statistician
  6. {
  7. public:
  8. void next(double r);
  9.  
  10. private:
  11. int count;
  12. };
  13. }
  14.  
and the implementation file which contains now only the definitions:
Expand|Select|Wrap|Line Numbers
  1. #include "stats.h"
  2.  
  3. using namespace main_savitch_2C;
  4.  
  5.  
  6. void statistician::next(double r)
  7. {
  8.  
  9. }
  10.  
But when I try to compile this very simple program, the following error
occurs:

------ Build started: Project: Test, Configuration: Debug Win32 ------
Compiling...
statsimpl.cpp
Linking...
msvcrtd.lib(crtexe.obj) : error LNK2019: unresolved external symbol
_main referenced in function ___tmainCRTStartup
C:\Dokumente und Einstellungen\Patrick\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Debug\Assignment4.exe : fatal error LNK1120:
1 unresolved externals
Build log was saved at "file://c:\Dokumente und
Einstellungen\matti\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Assignment4\Debug\BuildL og.htm"
Assignment4 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

I look for the error for many hours but I simply do not find how I can
fix it :( Does anybody know here how I can fix this error?? :((

Regards

Sep 9 '06 #1
5 7131
pat270881 schrieb:
hello,

I use the Visual C++ 2005 Express Edition and I want to implement a
simple c++ programm which has a header file and a implementation file.
[snip]

Here the linker clearly states what he is missing:
msvcrtd.lib(crtexe.obj) : error LNK2019: unresolved external symbol
_main referenced in function ___tmainCRTStartup
You need to define a main() function:

int main() // or:
int main(int argc, char* argv[])

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 9 '06 #2

okay thank you very much! unfortunately I have one more problem, I have
now the following:

the header file:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. namespace main_savitch_2C
  4. {
  5. class statistician
  6. {
  7. public:
  8. void next(double r);
  9.  
  10. private:
  11.  
  12.  
  13. bool operator ==(const statistician& s1, const statistician& s2)
  14. {
  15. return true;
  16. }
  17.  
and my testfile:
[code]
#include <iostream // Provides cout, cin
#include "stats.h"

using namespace main_savitch_2C;
using namespace std;

int main(int argc, char* argv[])
{
statistician s1, s2, s3;
if (s1 == s2)
cout << "s1 and s2 are equal." << endl;
else
cout << "s1 and s2 are not equal." << endl;
}

I know that the operator== function is not correctly implemented yet
but I want only test the overall running of the program, I implement
this function later. The objects s1, s2 and s3 are from statistician
and contain above other variables a number. But when I run this
programm I get the following error:

------ Build started: Project: Assignment4, Configuration: Debug Win32
------
Linking...
stattest.obj : error LNK2019: unresolved external symbol "bool __cdecl
main_savitch_2C::operator==(class main_savitch_2C::statistician const
&,class main_savitch_2C::statistician const &)"
(??8main_savitch_2C@@YA_NABVstatistician@0@0@Z) referenced in function
_main
C:\Dokumente und Einstellungen\Patrick\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Debug\Assignment4.exe : fatal error LNK1120:
1 unresolved externals
Build log was saved at "file://c:\Dokumente und
Einstellungen\Patrick\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Assignment4\Debug\BuildL og.htm"
Assignment4 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

Do you know how I can fix this problem? Has this something to do with
the fact that the operator== is a non-member function??

Please help me once more.:(

Regards

Sep 9 '06 #3
pat270881 schrieb:
okay thank you very much! unfortunately I have one more problem, I have
now the following:

the header file:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. namespace main_savitch_2C
  3. {
  4.     class statistician
  5.     {
  6.     public:
  7.         void next(double r);
  8.     private:
  9. bool operator ==(const statistician& s1, const statistician& s2)
  10. {
  11.     return true;
  12. }
  13.  
This is obviously not your real code. There are some closing curly brackets
missing. Read this:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 9 '06 #4


What do you mean with that?? - This code is my real code, I try to get
it work, okay here once more my code:

The HEADER-File - stats.h:

#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
#include <iostream>

namespace main_savitch_2C
{
class statistician
{
public:
// CONSTRUCTOR
statistician( );
// MODIFICATION MEMBER FUNCTIONS
void next(double r);
void reset( );
// CONSTANT MEMBER FUNCTIONS
int length( ) const;
double sum( ) const;
double mean( ) const;
double minimum( ) const;
double maximum( ) const;
// FRIEND FUNCTIONS
friend statistician operator +
(const statistician & s1, const statistician & s2);

private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tinyest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};

// NON-MEMBER functions for the statistician class
bool operator ==(const statistician& s1, const statistician& s2);
}

#endif

The implementation-file - statsimpl.cpp:

#include "stats.h"
#include <iostream>
using namespace main_savitch_2C;
statistician::statistician()
{
count = 0;
total = 0;
tinyest = 0;
largest = 0;
}

void statistician::next(double r)
{
total += r;
std::cout << total << std::endl;
}

int statistician::length() const
{
return 0;
}

void statistician::reset( )
{
count = 0;
total = 0;
tinyest = 0;
largest = 0;
}

double statistician::sum() const
{
return total;
}

double statistician::mean() const
{
return total/count;
}

double statistician::minimum() const
{
return tinyest;
}

double statistician::maximum() const
{
return largest;
}

bool operator ==(const statistician& s1, const statistician& s2)
{
return true;
}

statistician operator + (const statistician & s1, const statistician &
s2)
{
statistician s3;

s3.next(s1.sum() + s2.sum());

return s3;
}

And when I try to test this with this testfile - statstest.cpp:

#include <cctype // Provides toupper
#include <iomanip // Provides setw to set the width of an output
#include <iostream // Provides cout, cin
#include <cstdlib // Provides EXIT_SUCCESS
#include "stats.h"

using namespace main_savitch_2C;
using namespace std;

void print_menu( )
{
cout << endl;
cout << "The following choices are available: " << endl;
cout << " R Activate one of the reset( ) functions" << endl;
cout << " 1 Add a new number to the 1st statistician s1" << endl;
cout << " 2 Add a new number to the 2nd statistician s2" << endl;
cout << " 3 Add a new number to the 3rd statistician s3" << endl;
cout << " T Print a table of values from the statisticians" <<
endl;
cout << " E Test whether s1 == s2" << endl;
cout << " + Set the third statistician s3 equal to s1 + s2" <<
endl;
cout << " * Set the third statistician s3 equal to x*s1" << endl;
cout << " Q Quit this test program" << endl;
}

char get_user_command( )
// Library facilties used: iostream.h
{
char command;

cout << "Enter choice: ";
cin >command;

return command;
}

double get_number( )
// Library facilties used: iostream.h
{
double result;

cout << "Please enter the next real number for the sequence: ";
cin >result;
cout << result << " has been read." << endl;
return result;
}

void print_values(const statistician& s)
// Library facilties used: iostream.h
{
cout << setw(10) << s.length( );
cout << setw(10) << s.sum( );
if (s.length( ) != 0)
{
cout << setw(10) << s.minimum( );
cout << setw(10) << s.mean( );
cout << setw(10) << s.maximum( );
}
else
cout << " none none none";
cout << endl;
}

int main(int argc, char* argv[])
{
statistician s1, s2, s3; // Three statisticians for us to play with
char choice; // A command character entered by the
user
double x; // Value for multiplication x*s1

cout << "Three statisticians s1, s2, and s3 are ready to test." <<
endl;

do
{
cout << endl;
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case 'R': cout << "Which one should I reset (1, 2, 3) " << endl;
choice = get_user_command( );
switch (choice)
{
case '1': s1.reset( );
break;
case '2': s2.reset( );
break;
case '3': s3.reset( );
break;
}
cout << "Reset activated for s" << choice << "."
<< endl;
break;
case '1': s1.next(get_number( ));
break;
case '2': s2.next(get_number( ));
break;
case '3': s3.next(get_number( ));
break;

case '4': x = s1.sum();
cout << "Die Summe der Zahlen beträgt: " << x << endl;

x = s2.sum();
cout << "Die Summe der Zahlen beträgt: " << x << endl;
break;

case '+': s3 = s1 + s2;
cout << "s3 has been set to s1 + s2" << endl;
break;

case 'T': cout << "The values are given in this table:" <<
endl;
cout << " LENGTH SUM"
<< " MINIMUM MEAN MAXIMUM" << endl;
cout << " s1";
print_values(s1);
cout << " s2";
print_values(s2);
cout << " s3";
print_values(s3);
break;

case 'Q': cout << "Ridicule is the best test of truth." <<
endl;
break;
default: cout << choice << " is invalid. Sorry." << endl;
}
}
while ((choice != 'Q'));

return EXIT_SUCCESS;

}

I get the following error:

------ Build started: Project: Assignment4, Configuration: Debug Win32
------
Compiling...
statsimpl.cpp
Linking...
stattest.obj : error LNK2019: unresolved external symbol "class
main_savitch_2C::statistician __cdecl main_savitch_2C::operator+(class
main_savitch_2C::statistician const &,class
main_savitch_2C::statistician const &)"
(??Hmain_savitch_2C@@YA?AVstatistician@0@ABV10@0@Z ) referenced in
function _main
C:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Debug\Assignment4.exe : fatal error LNK1120:
1 unresolved externals
Build log was saved at "file://c:\Dokumente und
Einstellungen\matti\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Assignment4\Debug\BuildL og.htm"
Assignment4 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

This is the whole code, please help me with that, I simply can't find
the error...:((

Regards

matti

Sep 9 '06 #5
Hello Matti,

I don't have VC++ 2005 edition, so I tested your code on VC++ 2003
edition.

I made the following changes to get it working. Try making the same
changes at your end.

//Replace this function defination by the following defination
statistician operator + (const statistician & s1, const statistician &
s2)
{
statistician s3;

s3.next(s1.sum() + s2.sum());

return s3;

}

statistician main_savitch_2C::operator + (const statistician & s1,
const statistician &
s2)
{
statistician s3;

s3.next(s1.sum() + s2.sum());

return s3;

}

I hope this helps

Best Regards
-Amit Gupta

pat270881 wrote:
What do you mean with that?? - This code is my real code, I try to get
it work, okay here once more my code:

The HEADER-File - stats.h:

#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
#include <iostream>

namespace main_savitch_2C
{
class statistician
{
public:
// CONSTRUCTOR
statistician( );
// MODIFICATION MEMBER FUNCTIONS
void next(double r);
void reset( );
// CONSTANT MEMBER FUNCTIONS
int length( ) const;
double sum( ) const;
double mean( ) const;
double minimum( ) const;
double maximum( ) const;
// FRIEND FUNCTIONS
friend statistician operator +
(const statistician & s1, const statistician & s2);

private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tinyest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};

// NON-MEMBER functions for the statistician class
bool operator ==(const statistician& s1, const statistician& s2);
}

#endif

The implementation-file - statsimpl.cpp:

#include "stats.h"
#include <iostream>
using namespace main_savitch_2C;
statistician::statistician()
{
count = 0;
total = 0;
tinyest = 0;
largest = 0;
}

void statistician::next(double r)
{
total += r;
std::cout << total << std::endl;
}

int statistician::length() const
{
return 0;
}

void statistician::reset( )
{
count = 0;
total = 0;
tinyest = 0;
largest = 0;
}

double statistician::sum() const
{
return total;
}

double statistician::mean() const
{
return total/count;
}

double statistician::minimum() const
{
return tinyest;
}

double statistician::maximum() const
{
return largest;
}

bool operator ==(const statistician& s1, const statistician& s2)
{
return true;
}

statistician operator + (const statistician & s1, const statistician &
s2)
{
statistician s3;

s3.next(s1.sum() + s2.sum());

return s3;
}

And when I try to test this with this testfile - statstest.cpp:

#include <cctype // Provides toupper
#include <iomanip // Provides setw to set the width of an output
#include <iostream // Provides cout, cin
#include <cstdlib // Provides EXIT_SUCCESS
#include "stats.h"

using namespace main_savitch_2C;
using namespace std;

void print_menu( )
{
cout << endl;
cout << "The following choices are available: " << endl;
cout << " R Activate one of the reset( ) functions" << endl;
cout << " 1 Add a new number to the 1st statistician s1" << endl;
cout << " 2 Add a new number to the 2nd statistician s2" << endl;
cout << " 3 Add a new number to the 3rd statistician s3" << endl;
cout << " T Print a table of values from the statisticians" <<
endl;
cout << " E Test whether s1 == s2" << endl;
cout << " + Set the third statistician s3 equal to s1 + s2" <<
endl;
cout << " * Set the third statistician s3 equal to x*s1" << endl;
cout << " Q Quit this test program" << endl;
}

char get_user_command( )
// Library facilties used: iostream.h
{
char command;

cout << "Enter choice: ";
cin >command;

return command;
}

double get_number( )
// Library facilties used: iostream.h
{
double result;

cout << "Please enter the next real number for the sequence: ";
cin >result;
cout << result << " has been read." << endl;
return result;
}

void print_values(const statistician& s)
// Library facilties used: iostream.h
{
cout << setw(10) << s.length( );
cout << setw(10) << s.sum( );
if (s.length( ) != 0)
{
cout << setw(10) << s.minimum( );
cout << setw(10) << s.mean( );
cout << setw(10) << s.maximum( );
}
else
cout << " none none none";
cout << endl;
}

int main(int argc, char* argv[])
{
statistician s1, s2, s3; // Three statisticians for us to play with
char choice; // A command character entered by the
user
double x; // Value for multiplication x*s1

cout << "Three statisticians s1, s2, and s3 are ready to test." <<
endl;

do
{
cout << endl;
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case 'R': cout << "Which one should I reset (1, 2, 3) " << endl;
choice = get_user_command( );
switch (choice)
{
case '1': s1.reset( );
break;
case '2': s2.reset( );
break;
case '3': s3.reset( );
break;
}
cout << "Reset activated for s" << choice << "."
<< endl;
break;
case '1': s1.next(get_number( ));
break;
case '2': s2.next(get_number( ));
break;
case '3': s3.next(get_number( ));
break;

case '4': x = s1.sum();
cout << "Die Summe der Zahlen beträgt: " << x << endl;

x = s2.sum();
cout << "Die Summe der Zahlen beträgt: " << x << endl;
break;

case '+': s3 = s1 + s2;
cout << "s3 has been set to s1 + s2" << endl;
break;

case 'T': cout << "The values are given in this table:" <<
endl;
cout << " LENGTH SUM"
<< " MINIMUM MEAN MAXIMUM" << endl;
cout << " s1";
print_values(s1);
cout << " s2";
print_values(s2);
cout << " s3";
print_values(s3);
break;

case 'Q': cout << "Ridicule is the best test of truth." <<
endl;
break;
default: cout << choice << " is invalid. Sorry." << endl;
}
}
while ((choice != 'Q'));

return EXIT_SUCCESS;

}

I get the following error:

------ Build started: Project: Assignment4, Configuration: Debug Win32
------
Compiling...
statsimpl.cpp
Linking...
stattest.obj : error LNK2019: unresolved external symbol "class
main_savitch_2C::statistician __cdecl main_savitch_2C::operator+(class
main_savitch_2C::statistician const &,class
main_savitch_2C::statistician const &)"
(??Hmain_savitch_2C@@YA?AVstatistician@0@ABV10@0@Z ) referenced in
function _main
C:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Debug\Assignment4.exe : fatal error LNK1120:
1 unresolved externals
Build log was saved at "file://c:\Dokumente und
Einstellungen\matti\Eigene Dateien\Visual Studio
2005\Projects\Assignment4\Assignment4\Debug\BuildL og.htm"
Assignment4 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

This is the whole code, please help me with that, I simply can't find
the error...:((

Regards

matti
Sep 9 '06 #6

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...
0
by: Ida | last post by:
Hi, I am trying to build an dll with Microsoft Visual C++ but during the linking phase I get linking errors. Script.obj : error LNK2019: unresolved external symbol __imp__PyString_AsString...
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: ...
2
by: Maydogg6 | last post by:
I need a hand with some stubborn link errors. I'm trying to recreate and old program from 6.0 into .NET, but for some reason when I try to compile I'm getting linking errors for all my function...
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: 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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.