看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) GCC Linux 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 關於floor使用上的問題,直接以程式碼說明比較快。 前提 double i = 11.22; 情形1. int tmp = (int)floor(11.22); <---沒有錯 情形2. int tmp = (int)floor(i); <---得到錯誤 undefined reference to "floor" 情形3. double tmp = floor(i); <---得到錯誤 undefined reference to "floor" 請問,為什麼會這樣子呢...>"< 找到解決的辦法了,雖然我覺得很奇怪 ~"~ 我在Setting-->compiler And Debugger-->Compiler Flags 的地方勾選了 Optimize even more (for Speed) [-O2] 然後...用code block 的Compile就不會有錯誤了....(默) 我還是乖乖用命令視窗好了 Orz -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.251.71.22
LPH66:你有 #include <math.h> 嗎 @_@ 04/15 14:16
uranusjr:沒 inlude math.h 應該連第一個都不會過才對... 04/15 14:21
james732:請用 gcc 檔名.c -lm 試試看 04/15 14:23
shiengchyi:我有#include <math.h> 04/15 14:36
shiengchyi:也用過命令視窗執行gcc 但是就是有錯 0.0a 04/15 14:37
shiengchyi:程式碼就只有那兩行 囧> 04/15 14:38
james732:你有加「-lm」嗎? 04/15 14:40
shiengchyi:-lm之後 沒有錯了...不過在code block上compile有錯 04/15 14:41
shiengchyi:所以問題是出在codeBlock對math.h的linker上面?! 04/15 14:42
james732:你上一篇不是說解決了,為什麼現在又說有錯...?? 04/15 14:43
Fenikso:常數被compiler偷展開算掉 所以免link 04/15 14:43
shiengchyi:@@a 還有這招喔 04/15 14:45
shiengchyi:因為上一篇我拿常數去做測試 >"< 04/15 14:45
purpose:可以翻一下說明書 04/15 14:48
Fenikso:總之加-lm絕對不會錯.. compiler的行為你先不要管 04/15 14:53
※ 編輯: shiengchyi 來自: 60.251.71.22 (04/15 15:03)
LPH66:那個選項做的是另一件事...和這裡說的 -lm 完全無關 = = 04/15 15:27
LPH66:至於它做了什麼事你現在不必要知道原因 04/15 15:27
shiengchyi:那個選項就是GCC的-O2 只是為什麼會有用就...XDDD 04/15 15:34
LPH66:我大概猜得到為什麼 不過這就已經和 -lm 無關了 04/15 15:51