头文件似乎无法正常工作。
我是C语言的新手,真的不知道我在做什么
error - findvals.c:(.text+0x561): undefined reference to `approxEqual'
findvals.c
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
int main(int argc, char **argv)
{
//printf("GRR ENTAR SOMETHANG");
//char word[64];
//scanf("%s", word);
int count = 0;
int ret;
double x;
double y;
int i = 0;
int c = 0;
char *refStr, *tolStr;
double refDub;
double tolDub;
int noArgs = 0;
//double temp;
//scanf("%lf" , &temp);
//printf("DUBBB %lf" , temp);
refStr = tolStr = NULL;
//Add code to read arguments, in ANY order i.e. -r can come before or after -t
int processCount = 0;
for(i = 1; i < 5; i++)
{
if (strcmp(argv[i], "-r"))
{
tolStr = argv[i+1];
i++;
//printf("\nIM HERE r");
}
else if (strcmp(argv[i], "-t"))
{
refStr = argv[i+1];
i++;
//printf("\nIM HERE t");
}
}
refDub = atof(refStr);
tolDub = atof(tolStr);
//printf("\nrefDub = %f", refDub);
//printf("\ntolDub = %f", tolDub);
//Check if arguments were passed in correctly.
if (argc != 5 || refStr == NULL || tolStr == NULL)
{
fprintf(stderr, "Usage: %s -r ref -t tol\n", argv[0]);
exit(1);
}
//Add code to note start time and date and then print it.
//Right now printing just a default string
struct tm *local;
time_t start, end;
time(&start); // read and record clock
local = localtime(&start);
printf("\n# Start time and date: %s", asctime(local));
//char * tnd="Wed 15 Oct 2014 19:18:13 IST";
//printf("# Start time and date: %s", tnd );
// Add rest of the functionality.
//READ
int rows; // Sixe x axis of the array
int cols; // Sixe y axis o the array
scanf("%d" , &rows);
scanf("%d" , &cols);
double opArray[rows][cols]; // Array for operations
for(i = 0 ; i < rows; i++)
{
for(c = 0 ; c < cols; c++)
{
scanf("%lf" , &opArray[i][c]);
}
}
//read in the matrix
double **mat = (double **) malloc(sizeof(double *)*rows);
int j=0;
for(i=0; i<rows; i++)
/* Allocate array, store pointer */
mat[i] = (double *) malloc(sizeof(double)*cols);
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
scanf("%lf",&mat[i][j]);
}
}
// The following print statement should be a part of a loop
// Uncomment it tailor it to your code but ONLY the part that
// comes after: \n",
// fprintf(stdout, "r=%d, c=%d: %.6f\n", r, c, rows[r][c]);
for(i= 0; i < rows ; i++)
{
for(j = 0 ; j <cols ; j++)
{
ret = approxEqual(mat[i][j],refDub,tolDub);
if (ret == 1)
{
fprintf(stdout, "r=%d, c=%d: %.6f\n", i, j, mat[i][j]);
count++;
}
}
}
// output the final count of matches. Again, you may ONLY modify
// the part of the print statement after: \n",
// fprintf(stdout, "Found %d approximate matches.\n", count);
//finally, print out the end time and date. Right now only printing
//a default string.
time(&end); // read and record clock
local = localtime(&end);
printf("\n# End time and date: %s", asctime(local));
exit(0);
}
实用程序
#include "utils.h"
int approxEqual(double x, double r, double t)
{
int ceiling = r+t;
int floored = r-t;
if(x > floored && x < ceiling)
return 1;
else
return 0;
}
实用程序
#if ! defined(UTILS_H)
#define UTILS_H
int approxEqual(double x, double r, double t);
#endif
如果有人能指出我正确的方向,那将是很棒的
我是如何编译的
gcc -c utils.c
gcc findvals.o utils.o -o findvals
gcc -c findvals.c
最佳答案
gcc -c utils.c findvals.c utils.h
gcc findvals.o utils.o -o findvals
检查一下。这将起作用。
关于c - 头文件不起作用-未定义对`method'的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26599004/