我一直在試圖建立一個使用數學函數的一些代碼(例如pow
)。gcc和math.h的奇怪行爲?
math.h
被包括,並且標誌-lm
在構建期間使用。
當編譯這樣調用(-lm
標誌在命令的開頭),它失敗了,說是有一個未定義的參考pow
:
gcc -lm -O3 main.o clustering.o grassberger.o hash.o list.o mat.o metropolis.o motif_ids.o output.o permutation.o prob.o random.o results.o role.o stubs.o switches.o -o mfinder
main.o: In function `get_sn_motif_id':
main.c:(.text+0x28d): undefined reference to `pow'
而當-lm
標誌被放置在命令的結尾,它的作品!
gcc -O3 main.o clustering.o grassberger.o hash.o list.o mat.o metropolis.o motif_ids.o output.o permutation.o prob.o random.o results.o role.o stubs.o switches.o -o mfinder -lm
這是正常的嗎?
哎呀。沒有注意到這是一個古老的問題。 – AnT