2011-10-12 63 views
1

可能存在什么原因,即使设置了标志-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; 

    } 
} 
+0

在这段代码中,你似乎使用'-Im'而不是'-lm'?它应该是小写字母L – poundifdef

+0

为什么在命令行中输入'-Im'而不是'-lm'? (并不是说这与编译错误有关)。 –

+0

您需要在65-75行附近张贴代码,并且还会显示您包含的内容 –

回答

3

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

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

我添加了违规代码。 – Framester

+1

@Framester老实说,虽然你应该包含'cmath'而不是'math.h'。 – cnicutar

+0

割草我得到错误'template_gold.cpp:69:错误:'abs'不是'std''的成员 – Framester

相关问题