【发布时间】:2011-12-06 02:32:24
【问题描述】:
可能是什么原因,即使我设置了标志-lm,gcc 也没有链接到math.h?
me@mycomputer$ 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 -
为什么你在命令行中有
-Im而不是-lm? (并不是说这与您的编译错误有关)。 -
您需要在第 65 - 75 行附近发布代码,并显示您拥有的#includes
-
感谢您的快速回复,但那是我输入的,我更正了。 (我什至试过 -Im,以防我误读了帖子......)