即使设置了“-lm”,也找不到 Math.h
即使我设置了标志 -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;
}
}
What causes could there be, that gcc does not link to math.h
even though I set the flag -lm
?
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
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能忘记使用
std::max
,或者忘记添加using namespace std
。尝试You probably forgot to use
std::max
, or you forgot addingusing namespace std
. Try