error LNK2001: unresolved external symbol

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 3
Reputation: HConn is an unknown quantity at this point 
Solved Threads: 0
HConn HConn is offline Offline
Newbie Poster

error LNK2001: unresolved external symbol

 
0
  #1
Oct 28th, 2004
I am trying to write a program that computes the area of a right triangle. It has to use a function to compute the area. This is actually a part of a bigger program, but when I couldn't get it to work I isolated this section. I tried looking on google for help, but nothing I found seemed to help. I get no errors when I compile, but when I try to execute I get the following error:

Linking...
area.obj : error LNK2001: unresolved external symbol "double __cdecl findarea(double,double)" (?findarea@@YANNN@Z)
Debug/area.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

area.exe - 2 error(s), 0 warning(s)
Below is my code:

  1. //Program to compute the area of a right triangle
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5.  
  6.  
  7.  
  8. //Declare std
  9. using std::cout;
  10. using std::cin;
  11. using std::endl;
  12. using std::ios;
  13. using std::cerr;
  14. using std::ofstream;
  15.  
  16. //Function Prototype
  17. double findarea (double,double);
  18.  
  19. //Start the program
  20. int main ()
  21. {
  22.  
  23. //Declare the variables
  24. double a; //side a
  25. double b; //side b
  26. double d; //area
  27.  
  28.  
  29. //Open the file for output
  30. ofstream datafile ("program.txt", ios::out);
  31.  
  32. //Error routine if file can not be created
  33. if (!datafile) {
  34. cerr << "File could not be opened" << endl;
  35. exit (1);
  36. }
  37.  
  38. //Initialize a
  39. a=1;
  40.  
  41. //Describe program to user
  42. cout << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program.";
  43. datafile << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program.";
  44.  
  45. //Begin the WHILE loop to set sentinal value to loop the program
  46. while (a>0){
  47.  
  48.  
  49. //Get a
  50. cout << "\n\nEnter the length of side a: " << endl;
  51. cin >> a;
  52. datafile << "\n\nSide a is: " << a << endl;
  53.  
  54. //Use an IF to dictate the behavior of the program if a>0 and get b
  55. if (a>0){
  56. cout << "\nEnter the length of side b: " << endl;
  57. cin >> b;
  58. datafile <<"Side b is: " << b << endl;
  59.  
  60. //Allow for b<=0
  61. if (b<=0){
  62. cout << "\n\nYou have ended the program." << endl;
  63. datafile << "You have ended the program." << endl;
  64. break;
  65. }
  66.  
  67. d=findarea(a,b);
  68.  
  69. cout << "\nThe area is: " << d << endl;
  70. datafile << "The area is: " << d << endl;
  71.  
  72. //End IF
  73. }
  74.  
  75. //Start ELSE to allow output that tells the user they have ended the program
  76. else {
  77. cout << "\n\nYou have ended the program." << endl;
  78. datafile << "You have ended the program." << endl;
  79.  
  80. //End ELSE
  81. }
  82.  
  83.  
  84. //End WHILE
  85. }
  86.  
  87. //End program
  88. return 0;
  89.  
  90. }
  91.  
  92.  
  93.  
  94. double findarea (double q,double r,double s) {
  95. s=(q*r)/2;
  96. return s;
  97. }

Any pointers/help would be appreciated.

TIA
Heather
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,612
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error LNK2001: unresolved external symbol

 
0
  #2
Oct 28th, 2004
Compare and contrast:

>double findarea (double,double);
>d=findarea(a,b);
>double findarea (double q,double r,double s) {

Be sure to take careful note that the declaration takes two arguments and the definition takes three. C++ treats these as two unique functions that are overloaded to have the same name, therefore the linker is complaining about your not defining the findarea that takes two arguments.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3
Reputation: HConn is an unknown quantity at this point 
Solved Threads: 0
HConn HConn is offline Offline
Newbie Poster

Re: error LNK2001: unresolved external symbol

 
0
  #3
Oct 28th, 2004
Thanks so much :cheesy: I had a feeling it was something simple I was overlooking. It was driving me bonkers
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,612
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error LNK2001: unresolved external symbol

 
0
  #4
Oct 29th, 2004
>I had a feeling it was something simple I was overlooking.
That's not really something simple, so don't feel bad. Function overloading problems tend to be incredibly subtle and difficult to find, even for experienced C++ programmers.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3
Reputation: HConn is an unknown quantity at this point 
Solved Threads: 0
HConn HConn is offline Offline
Newbie Poster

Re: error LNK2001: unresolved external symbol

 
0
  #5
Nov 2nd, 2004
Part of my confusion came from the fact I had done a different program set up the same way... prototyped-(double, double) invoked-(a,b) then defined-(double x, double y, double z) for finding the hypotenuse of a right triangle...and it compiled and linked and worked fine for whatever fluke reason. Then we had to make it also do the area and I set it up like I had the hypotenuse function...and the hypotenuse still worked but then the area part errored out. So I pulled the area part of it and made a program just for that....it still errored on the linking...I couldn't figure out why, so that is why I came on here yelling for help. My teacher even said "I can tell you why the area function did NOT work, but I can't explain why the hypotenuse one DID work." Just a fluke thing that for some reason I got away with. So now I know...lol
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC