Reputation: 21
here is my code it is very simple in the end all it is going to do is prompt the user to input the size of two 2d arrays and then input the entries and multiple the result as if they were mathmatical matrix. the program is far from done but i like to compile thesesmall programs as i go to see if the all parts are working. when i compile this code i get this odd error. note i am very much a beginner when i comes to C++ as well as coding in general.
$ g++ matrix.C -omatrixs -lm
/tmp/ccUDYTb1.o:matrix.C:(.text+0x266): undefined reference to `Matrixsettings(int, int, int, int)'
/tmp/ccUDYTb1.o:matrix.C:(.text+0x266): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Matrixsettings(int, int, int, int)'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccUDYTb1.o: bad reloc address 0x1c in section `.xdata'
collect2: error: ld returned 1 exit status
i am using cygwin 64bit with a gnu compiler and notepad++ to compile and write this.
#include <iostream>
#include <cmath>
using namespace std;
//Prototypes
double Matrixsettings(int, int, int, int);
int main()
{
int a=2, b=2, c=2, d=2;
int m1 [a] [b], m2 [c] [d];
cout<< Matrixsettings( a,b,c,d);
cout<< a<<b<<c<<d;
return 0;
}
double Matrixsettings( int &a, int &b, int &c, int &d)
{
cout<< "how many rows in the first matrix: ";
cin>> a;
cout<< "how many columns in the first matrix: ";
cin>> b;
cout<< "how many rows in the second matrix: ";
cin>> c;
cout<< "how many columns in the second matrix: ";
cin>> d;
return 0;
}
Upvotes: 2
Views: 3466
Reputation: 17956
This is incorrect:
double Matrixsettings(int, int, int, int);
The correct prototype for the actual function you have is:
double Matrixsettings(int&, int&, int&, int&);
You want to fix the prototype, and not the function, because your function actually writes to its parameters a
, b
, c
, and d
.
The error message indicates that the compiler made a call to the function you declared in the prototype (since it matched the arguments you gave), but the linker couldn't find a function that matched the name Matrixsettings
but took four int
arguments (not int&
).
The "truncated relocation" error was just a consequence of the first error—a cascade error of sorts. Fixing the first error will fix both errors.
Upvotes: 2
Reputation: 182827
First you say Matrixsettings
takes four integers, then you say it takes four references to integers. You need to chose one and stick with it.
Change:
double Matrixsettings(int, int, int, int);
to:
double Matrixsettings(int&, int&, int&, int&);
Upvotes: 1