可能存在什麼原因,即使設置了標誌-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;
}
}
在這段代碼中,你似乎使用'-Im'而不是'-lm'?它應該是小寫字母L – poundifdef
爲什麼在命令行中輸入'-Im'而不是'-lm'? (並不是說這與編譯錯誤有關)。 –
您需要在65-75行附近張貼代碼,並且還會顯示您包含的內容 –