I had part of a polynomial multiplier program running in Xcode but after I added and deleted some code that wasn't working I got a build error.
1 2 3 4 5
Undefined symbols for architecture x86_64:
"multiply(int, int, int&, int*, int*, int*)", 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)
The program also failed to compile in Unix g++ and produced this error:
1 2 3 4
g++ -o polytest polytest.cpp
/tmp/ccHDBod8.o: In function `main':
polytest.cpp:(.text+0x351): undefined reference to `multiply(int, int, int&, int*, int*, int*)'
collect2: error: ld returned 1 exit status
Whatever it is, It probably has something to do with the "multiply" function call which is passing dynamic arrays, since deleting it stops the error.
Q1 - do you have a multiply function in your code at all?
If you do, is this it's signature?
> multiply(int, int, int&, int*, int*, int*)
If not, then you need to change either (or both) of
- how you call it (pass different parameters)
- how you implement it (accept the parameters you're trying to pass).
Sounds like a linker error. For XCode there are 2 steps to link.
For example if you have a header and corresponding implementation file aaa.h and aaa.cp (or.cpp etc) where the relevant function(s) are written and main looks like:
STEP 1. Add the header file to the (main) file.
STEP 2. In XCode click on the project icon at the top LH file directory/navigator. On the RHS select TARGETS -> Build phases -> Compile Sources and then add (+) both aaa files to the list (probabaly via the 'Other' button)
@salem c
There is both a multiply function call and a multiply function definition. The first three parameters are just regular 'int's (not sure why the third is treated as a call-by-reference). The other three are pointers to 'int' arrays that are used as such:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
typedefint* polyptr; // before main()
// declarations in main()
polyptr polynomial1;
polyptr polynomial2;
polyptr polynomialproduct;
// creating dynamic arrays
polynomial1 = newint[degree1];
polynomial2 = newint[degree2];
polynomialproduct = newint[degree3];
// function call
multiply(degree1, degree2, degree3, polynomial1, polynomial2, polynomialproduct);
// function definition
void multiply(int deg1, int deg2, int deg3, int poly1[], int poly2[], int poly3[])
@againtry
I just created aaa.hpp and aaa.cpp in the same folder as main.cpp and added them in Compile Sources. Same linker error. Do you want me to move the function definition of "multiply" out of main.cpp and put it in aaa.cpp?
> not sure why the third is treated as a call-by-reference
perhaps you declared it as such
if you are using just one file, i bet on your prototypes (declaration/definition) don't match
¿shouldn't be `degree3' calculated inside the multiply() function?
> void multiply(int deg1, int deg2, int deg3, int poly1[], int poly2[], int poly3[])
So why does the linker error message look like this?
> multiply(int, int, int&, int*, int*, int*)
You need to figure out whether you mean int or int&, and then fix the appropriate thing.