我遇到了以下错误:
main.o(.text+0x1ed): In function `main':
: undefined reference to `avergecolumns'
collect2: ld returned 1 exit status
当我运行“gcc *.o”时,我不太确定是什么导致了这个错误。其他帖子中已经将其解释为未找到函数或函数为空。如果有人能澄清或完善一下,那将不胜感激!
这是我的函数代码(我正在尝试计算2D数组列的平均值):
#include "my.h"
void averagecolumns (int x, int y, int** a)
{
int i;
int j;
float sum;
float colAvg;
sum = 0;
colAvg = 0;
printf("i. The column averages are: \n");
for(i = 0; i < x; i++)
{
for(j = 0; j < y; j++)
{
sum += a[i][j];
colAvg = sum / (float)x;
}
printf("Column: %3d, Average: %6.2f", j, colAvg);
sum = 0;
colAvg = 0;
}
相关的主要部分是:
#include "my.h"
int main (int argc, char* argv[])
{
int** a;
float** colAvg;
int ROWS;
int COLS;
int i;
int j;
int** table;
FILE* fpmyfile;
int closeResult;
....
printme (ROWS, COLS, a); // call functions a - j
oddvalues (ROWS, COLS, a);
oddlocations (ROWS, COLS, a);
countoddrows (ROWS, COLS, a);
addrows (ROWS, COLS, a);
findfirstsmall (ROWS, COLS, a);
findlastlarge (ROWS,COLS, a);
addcolumns (ROWS, COLS, a);
avergecolumns (ROWS, COLS, a);
....
}
另外,这是链接错误还是编译错误(我不确定应该添加哪个标签)。
averageColumns
或average_columns
都比averagecolumns
更容易发现。 - Aaron Dufour