[問題] 書上範例編譯失敗(數值分析 使用C語言)
範例來自數值分析 使用C語言 程曉旭 耿魯靜 張海 王勇
http://www.wunanbooks.com.tw/product/9789865836108
第二章 複數的四則運算
開發平台(Platform):ubuntu 13.04 ,gcc 4.7.3
main function: http://ideone.com/YUs2Os
other functions: http://ideone.com/m2LeIL
http://ideone.com/hJrvlR
我將main function 和 other functions 放在同一資料夾
然後 gcc 編譯 main function,出現以下錯誤訊息:
c_comp_examplel.c:1:20: fatal error: c_comp.h: No such file or directory
compilation terminated.
如果我將main function的 #include "c_comp.h" 去掉也無法編譯
會產生以下的錯誤訊息:
In file included from c_comp_divide.c:12:0,
from c_comp_examplel.c:6:
c_comp_product.c:12:8: error: redefinition of ‘struct c_comp’
In file included from c_comp_examplel.c:5:0:
c_comp_product.c:12:8: note: originally defined here
In file included from c_comp_divide.c:12:0,
from c_comp_examplel.c:6:
c_comp_product.c:15:2: error: conflicting types for ‘c_comp’
In file included from c_comp_examplel.c:5:0:
c_comp_product.c:15:2: note: previous declaration of ‘c_comp’ was here
In file included from c_comp_divide.c:12:0,
from c_comp_examplel.c:6:
c_comp_product.c:16:5: error: redefinition of ‘c_comp_product’
In file included from c_comp_examplel.c:5:0:
c_comp_product.c:16:5: note: previous definition of ‘c_comp_product’ was here
In file included from c_comp_examplel.c:6:0:
c_comp_divide.c:13:8: error: redefinition of ‘struct c_comp’
In file included from c_comp_divide.c:12:0,
from c_comp_examplel.c:6:
c_comp_product.c:12:8: note: originally defined here
In file included from c_comp_examplel.c:6:0:
c_comp_divide.c:16:2: error: conflicting types for ‘c_comp’
In file included from c_comp_examplel.c:5:0:
c_comp_product.c:15:2: note: previous declaration of ‘c_comp’ was here
我想請問的是~
是我的編譯方式有問題嗎?
或者是書上有範例有錯?
謝謝大家耐心看完
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.46.220
推
10/02 21:56, , 1F
10/02 21:56, 1F
範例光碟 還有書本裡並沒有附此檔案
我google "c_comp.h"之後 也是一頭霧水
推
10/02 21:57, , 2F
10/02 21:57, 2F
→
10/02 21:58, , 3F
10/02 21:58, 3F
可以請S大再稍微給點題示嗎?
推
10/02 22:03, , 4F
10/02 22:03, 4F
→
10/02 22:03, , 5F
10/02 22:03, 5F
→
10/02 22:04, , 6F
10/02 22:04, 6F
→
10/02 22:05, , 7F
10/02 22:05, 7F
→
10/02 22:06, , 8F
10/02 22:06, 8F
→
10/02 22:09, , 9F
10/02 22:09, 9F
→
10/02 22:10, , 10F
10/02 22:10, 10F
→
10/02 22:11, , 11F
10/02 22:11, 11F
→
10/02 22:13, , 12F
10/02 22:13, 12F
十分感謝大家的建議
(尤其是S大熱心修改code,我會仔細比較您和書中範例的差異)
原本範例中printf(" ")裡的雙引號還是全形的 printf(” ”),
我後來修改過才PO上來給大家看 囧rz
推
10/02 22:25, , 13F
10/02 22:25, 13F
→
10/02 22:34, , 14F
10/02 22:34, 14F
推
10/02 22:35, , 15F
10/02 22:35, 15F
→
10/02 22:42, , 16F
10/02 22:42, 16F
→
10/02 22:54, , 17F
10/02 22:54, 17F
→
10/02 22:55, , 18F
10/02 22:55, 18F
我剛才隨手從後面翻了兩個範例,其中一個還是compile不過,
另外一個作者忘記附在電子檔裡了。
(書中有寫電子檔的名稱,可是我從光碟找不到該檔案 囧rz)
推
10/02 23:11, , 19F
10/02 23:11, 19F
→
10/02 23:23, , 20F
10/02 23:23, 20F
→
10/03 02:22, , 21F
10/03 02:22, 21F
→
10/03 02:23, , 22F
10/03 02:23, 22F
→
10/03 08:13, , 23F
10/03 08:13, 23F
→
10/03 08:14, , 24F
10/03 08:14, 24F
→
10/03 08:15, , 25F
10/03 08:15, 25F
→
10/03 08:17, , 26F
10/03 08:17, 26F
→
10/03 15:25, , 27F
10/03 15:25, 27F
→
10/03 15:26, , 28F
10/03 15:26, 28F
感謝推薦,我借到了 Numerical Recipes in C; Algorithms_3rd; Algorithms.in.c;
以上三本書,
不過都沒有含範例程式 不知道哪本比較詳盡好讀
另外d大提到碁峰的書 請問有特別推哪一本嗎?
※ 編輯: plasmajohn 來自: 140.116.46.220 (10/04 03:06)
→
10/04 10:20, , 29F
10/04 10:20, 29F
→
10/04 10:23, , 30F
10/04 10:23, 30F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章