-1

Undefined symbols for architecture x86_64:
"standardDeviation(double*)", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

#include <iostream>
using namespace std;

double standardDeviation(double []);

int main(){
    double array[] =  {2, 11, 4, 5, 9, 5, 4, 12, 7, 8, 9, 3, 7, 4, 12, 10,9, 6, 9, 4};
    standardDeviation(array);
    return 0;
}

double standardDeviation(double arrary){
    cout << arrary;
    return 0.0;
}
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Zach
  • 33
  • 1
  • 6
  • your prototype is `[]`, your implementation is not. – KevinDTimm Nov 24 '15 at 21:36
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – KevinDTimm Nov 24 '15 at 21:37

1 Answers1

0

Your definition of standardDeviation is looking for a double which you are calling array. You are trying to pass in a array of doubles. The way c++ handles a array is it saves a location pointer to the variable name and when you give it a input (ex array[2]) it moves the space of that many doubles over in memory.

So what the compiler is complaining about is that you told it a double was coming and it got a pointer to a double.

Here's some info on pointers and arrays which should help flesh out what I stated above.

To fix this you should change your prototype to double standardDeviation(double array[]); and then copy that down to your function definition. (As noted by KevinDTrimm above)

Chris
  • 574
  • 7
  • 24
  • No, the linker is complaining that no method matches his call. It's not a pointer problem at all (besides the fact that pointers and scalars are not equal in method definitions) – KevinDTimm Nov 24 '15 at 21:41
  • @KevinDTimm The problem is that your prototype and function definition do not match (the prototype specifies array and the definition says it is a double). I expanded my answer explaining how to fix this. – Chris Nov 24 '15 at 21:47