gpt4 book ai didi

linux - 即使设置了 `-lm`,也找不到 Math.h

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:00:03 25 4
gpt4 key购买 nike

可能是什么原因导致 gcc 没有链接到 math.h,即使我设置了标志 -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

很抱歉,如果这是一个骗局,但搜索谷歌后我发现只有帖子建议设置 -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;

}
}

最佳答案

您可能忘记使用 std::max,或者您忘记添加 using namespace std。尝试

void void computeGold(valpoint* ..., centroid* ..., int ...)
{
using namespace std; /* or using std::max etc. */
}

关于linux - 即使设置了 `-lm`,也找不到 Math.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7740066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com