I want to pass an array from one cpp file to another.
first:
void wrapper(float **A,int N){
N=2;
printf("Allocating Matrices\n");
*A = (float*)malloc(N*N*sizeof(float));
for(int i = 0; i < N; ++i){
for (int j=0;j<N;j++){
*A[j+i*N] = i;
}
}
for(int i = 0; i < N; ++i) {
for (int j=0;j<N;j++){
printf("\nA_from=%f",*A[j+i*N]);
}
printf("\n");
}
}
second:
extern void wrapper(float **A,int N);
int main () {
int N=2;
float* A;
wrapper(&A,N);
for(int i = 0; i < N; ++i){
for (int j=0;j<N;j++){
printf("\nA_to=%f",A[j+i*N]);
}
printf("\n");
}
return 0;
}
I am compiling:
g++ -c -g first.cpp
g++ -c -g second.cpp
g++ -o run first.o second.o
and I am receiving:
multiple definition of `wrapper(float**, int)'
at first file