What causes could there be, that gcc does not link to math.h
even though I set the flag -lm
?
me@mycomputer开发者_StackOverflow中文版$ g++ template_gold.cpp -o template_gold -lm
template_gold.cpp: In function ‘void computeGold(valpoint*, centroid*, int)’:
template_gold.cpp:68: error: ‘max’ was not declared in this scope
template_gold.cpp:70: error: ‘abs’ was not declared in this scope
I am sorry, if this is a dupe, but searching the googles and SO I found only post suggesting to set the -lm
.
Offending Code
#include <math.h>
#include "kmeans.h"
extern "C"
void computeGold( valpoint* h_idata, centroid* h_centroids, int numClusters);
...
for (long valindex = 0; valindex<1024*1024; valindex++)
{
minDistance = 0xFFFFFFFF;
for (k = 0; k<numClusters; k++)
if (max((long)(h_idata[valindex].value - h_centroids[k].value))<minDistance)
{
minDistance = abs((long)(h_idata[valindex].value - h_centroids[k].value));
myCentroid = k;
}
h_idata[valindex].centroid = h_centroids[myCentroid].value;
}
}
You probably forgot to use std::max
, or you forgot adding using namespace std
. Try
void void computeGold(valpoint* ..., centroid* ..., int ...)
{
using namespace std; /* or using std::max etc. */
}
精彩评论