可能存在什么原因,即使设置了标志-lm
,gcc也不会链接到math.h
?尽管设置了-lm,Math.h仍未找到
[email protected]$ 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
我很抱歉,如果这是一个欺骗,但搜索谷歌,所以我只发现了张贴提示设置-lm
。
犯规代码
#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;
}
}
在这段代码中,你似乎使用'-Im'而不是'-lm'?它应该是小写字母L – poundifdef
为什么在命令行中输入'-Im'而不是'-lm'? (并不是说这与编译错误有关)。 –
您需要在65-75行附近张贴代码,并且还会显示您包含的内容 –