LNK errors

Hello, I am using multiple files and getting LNK errors.

here is the error list:
1>driver.obj : error LNK2019: unresolved external symbol "void __cdecl goodbye(void)" (?goodbye@@YAXXZ) referenced in function _main
1>driver.obj : error LNK2019: unresolved external symbol "double __cdecl eToTheN(double &)" (?eToTheN@@YANAAN@Z) referenced in function _main
1>functions.obj : error LNK2001: unresolved external symbol "double __cdecl eToTheN(double &)" (?eToTheN@@YANAAN@Z)
1>driver.obj : error LNK2019: unresolved external symbol "double __cdecl nthRoot(double &,int &)" (?nthRoot@@YANAANAAH@Z) referenced in function _main

Here are my files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//Header.h
#ifndef NUM_H
#define NUM_H

#include <iostream>
using namespace std;

//Description: Outputs a greeting
//Pre: None
//Post: User hello'd
void greeting();

//Description: Outputs the menu and returns the value entered by the user
//Pre: None
//Post: returns the user's input (even if invalid)
char outputMenu();

//Description: Keeps asking for user input until the number input is positive
//Pre: T is a numeric type
//Post: If doOutput = 1, output prompt. Returns a positive number specified by user
template <typename T>
T positiveInput(bool doOutput = 1)
{
  T input;
  do
  {
    if(doOutput)
      cout << "Enter a number: ";
    cin >> input;
    if(input <= 0)
      cout << "Must be positive" << endl;
  }while(input <= 0);
  return input;
}

//Description: Takes a number to an integer power
//Pre: Base is positive
//Post: Returns base to the power of pow
double exponent(double base, int pow); 

//Description: Calculate the nth root of a number
//Pre: Num is positive, num and original are same number on user's original call
//Post: returns the nth root of num
double nthRoot(double& num, int& n);

//Description: Calculates e to the power n
//Pre: n is an integer
//Post: returns e to the power n
double eToTheN(double& n);

//Description: Outputs a goodbye message
//Pre: None
//Post: User goodbye'd
void goodbye();

//Description: Calculates the factorial of a number
//ex: n! = n(n-1)(n-2)(n-3)...(1)
//Pre: n is positive
//Post: returns the factorial of the argument
int factorial(int n);

//Description: Calculates the hyperbolic sin of a number
//Pre: none
//Post: returns the hyperbolic sine of the arguement
double sinh(double num);
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//func.cpp
#include <iostream>
using namespace std;
#include "header.h"

void greeting()
{
  cout << "Hello Willie! I can tell your math skills are lacking so I will help you" << endl;
}

char outputMenu()
{
  char input;
  cout << "1) Enter a number" << endl
       << "2) Take the number to the power of another number" << endl
       << "3) Display the nth root of a number" << endl
       << "4) Calculate e ^ n" << endl
       << "5) Display the hyperbolic sine (sinh) of a number" << endl
       << "6) Quit";
  cin >> input;
  return input;
}
double exponent(double base, int power)
{
  double result = base;
  for(int i = 0; i < power -1; i++)
    result *= base;
  return result;
}

double nthRoot(double original, int m, const int n = 10)
{
  int num = original;
  for(int i = 1; i < n; i++)
    num += ((m - 1)*(num) + original/exponent(num, m - 1))/m;
  return num;
}
double eToTheN(int num, const int& n = 10)
{
  double result = 0;
  for(int i = 0; i < n; i++)
    result += exponent(num, i)/factorial(i);
  return result;
}
int factorial(int num)
{
  if (num != 0)
    return num * factorial(num - 1);
  return 1;
}
double sinh(double num)
{
  return (eToTheN(num) - eToTheN(num * -1))/2;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//main.cpp
//#includes
#include <iostream>
#include "header.h"
using namespace std;

//Body
int main()
{
  //Declarations
  bool entered = 0;
  const char enter = '1', power = '2', root = '3', ePower = '4', hypsin = '5', quit = '6';
  int powerInput;
  char userInput;
  double num;
  greeting();
  
  do
  {
    do
    {
      userInput = outputMenu();
      if(userInput < enter || userInput > quit)
        cout << "Must be between" << enter <<" and" << quit << endl;
    }while(userInput < enter || userInput > quit);
    if(userInput != enter && userInput != quit && !entered)
      cout << "Must enter" << enter << " first" << endl;
    else
      switch(userInput)
      {
        case enter://Enter a number
          num = positiveInput<double>();
          break;
        case power://Raise a num to a power
          cout << "Enter a number n to calculate " << num <<" ^ n:";
          powerInput = positiveInput<int>(0);
          cout << num << " ^ " << powerInput << " = " << exponent(num, powerInput) << endl;
          break;
        case root://Take the nth root of a num
          cout << "Enter a number n to calculate " << num << " ^ 1/n:";
          powerInput = positiveInput<int>(0);
          cout << num << " ^ 1/" << powerInput << " = " << nthRoot(num, powerInput) << endl;
          break;
        case ePower: //Take e ^ num
          cout << "e ^ " << num << " = " << eToTheN(num);
        case hypsin://Take the hyperbolic sine of num
          cout << "Sinh(" << num << ") = " << sinh(num);
          break;
      }
  }while(userInput != quit);
  goodbye();
}

Any help would be appreciated


Last edited on
The linker cannot find an object (compiled file) containing the following function definitions matching the parameters you're trying to use the functions with:

goodbye, eToTheN, nthRoot.

Looking through the code above, you've not defined goodbye at all, your definition of eToTheN accepts two variables but you're trying to call it with one variable only, and nthRoot accepts three variables but you're trying to use it with two.
Last edited on
Topic archived. No new replies allowed.