[問題] 書上範例編譯失敗(數值分析 使用C語言)

看板C_and_CPP (C/C++)作者 (張家安)時間12年前 (2013/10/02 21:54), 編輯推噓6(6024)
留言30則, 10人參與, 最新討論串1/1
範例來自數值分析 使用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
先找出c_comp.h吧
10/02 21:56, 1F
範例光碟 還有書本裡並沒有附此檔案 我google "c_comp.h"之後 也是一頭霧水

10/02 21:57, , 2F
把錯誤訊息很清楚的告訴你他找不到c_comp.h不是嗎?Y
10/02 21:57, 2F

10/02 21:58, , 3F
我看了 source code, 感覺寫得很不對勁啊 XD
10/02 21:58, 3F
可以請S大再稍微給點題示嗎?

10/02 22:03, , 4F
c_comp.h應該就是指那兩個function,不過source code可能要
10/02 22:03, 4F

10/02 22:03, , 5F
糟了是K&R function!
10/02 22:03, 5F

10/02 22:04, , 6F
改一下.
10/02 22:04, 6F

10/02 22:05, , 7F
出版日期2013/04/03這是怎麼一回事...
10/02 22:05, 7F

10/02 22:06, , 8F
我會建議換書比較快
10/02 22:06, 8F

10/02 22:09, , 9F
http://codepad.org/v4Xe0SQ7 書中範例還有bug是不允許的
10/02 22:09, 9F

10/02 22:10, , 10F
傳pointer也傳錯type,還include .c檔,作者好像不會寫C
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
XDDDD
10/02 22:25, 13F

10/02 22:34, , 14F
你們教授沒看過內容嗎...
10/02 22:34, 14F

10/02 22:35, , 15F
我們lab有買一本,明天來看看XDD
10/02 22:35, 15F
這本是我們教授推薦的自修書 我們lab買了三本 囧rz http://ppt.cc/rB9I

10/02 22:42, , 16F
怎麼還冒出第二位讀者, 這本書是很暢銷嗎? XDDD
10/02 22:42, 16F

10/02 22:54, , 17F
居然有三本,而且還分第一版和第二版...
10/02 22:54, 17F

10/02 22:55, , 18F
我想後面的範例應該會好一點,不致於compile不過了...吧?
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
比半夜看marvel板還恐怖 囧
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
抓全本Numerical Recipes in C下來卡實在。那也很老可是
10/03 15:25, 27F

10/03 15:26, , 28F
比K&R新一點。
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
numerical recipe不是都有程式碼嗎?其實他比較接近參考
10/04 10:20, 29F

10/04 10:23, , 30F
用途,程式之外有很詳細的推演,但沒有習題。
10/04 10:23, 30F
文章代碼(AID): #1IJ2MX7M (C_and_CPP)
文章代碼(AID): #1IJ2MX7M (C_and_CPP)