Linux 即使设置了“-lm”,也找不到Math.h

Linux 即使设置了“-lm”,也找不到Math.h,linux,linker,g++,Linux,Linker,G++,是什么原因导致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.

是什么原因导致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;

    }
}
#包括
#包括“kmeans.h”
外部“C”
void computeGold(valpoint*h_idata,形心*h_形心,int numClusters);
...

对于(long valindex=0;valindex您可能忘记了使用
std::max
,或者忘记了使用命名空间std添加
。请尝试

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

在这段代码中,您似乎在使用
-Im
而不是
-lm
?它应该是小写字母LW为什么命令行中有
-Im
,而不是
-lm
?(这与编译错误无关)。你需要在第65-75行附近发布代码,并显示包含的内容。谢谢你的快速回复,但那是我键入的,我更正了。(我甚至尝试了-Im,以防我误读帖子…)@Framester老实说,这并不是冒犯性的,尽管你应该包括
cmath
而不是
math.h
。我得到了错误
template\u gold.cpp:69:error:'abs'不是'std'的成员。
@Framester你有
包括
吗?