Function Referenced from Function: Symbol not Found

I'm getting this error from Xcode:
"digitsIn(int)", referenced from:
      binaryToDecimal(int)in Binary Conversion.o
      binaryToDecimal(int)in Binary Conversion.o
      binaryToDecimal(int)in Binary Conversion.o
      binaryToDecimal(int)in Binary Conversion.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


digitsIn (int) is a function I wrote in another application (given an integer, it finds the number of digits in that integer) . I've included it by including the header file from that application

1
2
3
4
5
6
7
8
// header.h from this project:
#include "[path to other project]/header.h"
#include <cmath>
#include <iostream>
using namespace std ;

int decimalToBinary (int const decimalNum) ;
int binaryToDecimal (int const binaryNum) ;

1
2
3
4
5
// header.h from other project:
#include <iostream>
using namespace std ;

int digitsIn (int const num) ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// from main.cpp (this project)
int binaryToDecimal (int const binaryNum) {
	int h = binaryNum ;
	int binaryNum_array [digitsIn (binaryNum) ] ;
	int decimalNum ;
	
	for (int i = 0 ; i <= digitsIn (binaryNum) ; i ++ ) {
		binaryNum_array [i] = h % 10 ;
		h /= 10 ;
		}
	
	for (int i = digitsIn (binaryNum) ; i >= 0 ; i -- ) {
		decimalNum += pow (d2, digitsIn (binaryNum) - i) ;
		}
	
	return decimalNum ;
	}
The implementation of digitsIn is not in any of the files that are compiled (cpp files in your current project), so compiler doesn't find it.
So I just add a reference to that .cpp file, right?
What do you mean be reference?
You could add that file to your project, or you could simply copy the function into one of your current files.
So I just add a reference to that .cpp file, right?

To clarify, you don't mean by this to #include the cpp file, right? This is not a good idea...
Last edited on
Topic archived. No new replies allowed.