2011-10-12 59 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

相關問題