I'm writing a code that takes 2D arrays and puts them into functions. They are then doing stuff with it and updating it. For a reason unknown to me however, I'm getting an undefined reference error even though I spent much time reading threads where people explained how to properly link .cpp and .h files. Let me show you the simplified code:
header.h
#ifndef HEADER_H
#define HEADER_H
const int N = 2;
const int rows = 206;
const double ptoSI = 2;
void getEOS(double etable[206][N], double ptable[206][N], double c_stable[206][N]);
#endif // HEADER_H
header.cpp
#include <iostream>
#include <fstream>
#include <math.h>
#include "header.h"
using namespace std;
void getEOS(double etable[206][N], double ptable[206][N], double c_stable[206][N]){
for (int i = 0; i<rows; i++){
for (int j = 0; j<N; j++){
etable[i][j] = cache[i][j*3]*1.60218E-13*1E45*1.0/(ptoSI);
ptable[i][j] = cache[i][j*3+1]*1.60218E-13*1E45*1.0/(ptoSI);
c_stable[i][j] = cache[i][j*3+2];
}
}
}
main.cpp
#include <iostream>
#include "header.h"
using namespace std;
int main()
{
double etable[rows][N];
double ptable[rows][N];
double c_stable[rows][N];
getEOS(etable,ptable,c_stable);
}
The error reads in detail:
/usr/bin/ld: main.o: in function `main':
/home/tux/build-testtext-Desktop_Qt_5_15_2_GCC_64bit-Debug/../testtext/main.cpp:13: undefined reference to `getEOS(double (*) [2], double (*) [2], double (*) [2])'
collect2: error: ld returned 1 exit status
make: *** [Makefile:274: testtext] Error 1
Why does he have a problem with this, even though I declared and defined the function properly?
Any help would be appreciated...
.pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
header.cpp \
main.cpp
HEADERS += \
header.h
I am using the following kit: Desktop Qt %{Qt:Version} GCC 64bit
Sorry,
if this code is professional, I would not let it pass in a review:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.