[問題] header 的問題....

看板C_and_CPP作者時間15年前 (2009/06/19 08:37), 編輯推噓9(906)
留言15則, 8人參與, 最新討論串1/1
大家好 我寫了個不小的程式所以把他們分成好幾個 .h .c A.h (include stdio.h) a.h (include stdio.h) b.h (include stdio.h) c.h (include stdio.h) d.h (include stdio.h) A.cpp (include A.h stdio.h) a.cpp (include A.h a.h) b.cpp (include A.h b.h) c.cpp (include A.h c.h) d.cpp (include A.h d.h) e.cpp (include A.h a.h b.h c.h d.h) 然後我用 gcc A.cpp a.cpp b.cpp c.cpp d.cpp e.cpp -o program 可是在 gcc 跟我說一堆東西已經在 A.h 定義過了........ 請問我應該要怎麼改呢?? 謝謝 <(_ _)> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 155.98.80.103

06/19 09:19, , 1F
去找找是哪些東西定義過 應該是你自己定義的東西重複定義
06/19 09:19, 1F

06/19 09:27, , 2F
你自己寫的.h有沒有用#ifndef #endif等括起來??
06/19 09:27, 2F

06/19 09:57, , 3F
隨便找一個.h來看看,如stdio.h,看他是怎麼解決重覆定義
06/19 09:57, 3F

06/19 10:35, , 4F
header檔不是沒有分大小寫嗎?
06/19 10:35, 4F

06/19 10:38, , 5F
gcc...所以在Unix-Like是有分大小寫?以前沒注意
06/19 10:38, 5F

06/19 11:12, , 6F
header檔真的沒有分大小寫??
06/19 11:12, 6F

06/19 11:12, , 7F
不是C都要分大小寫嗎?
06/19 11:12, 7F

06/19 11:18, , 8F
z大應該是指檔名; ex: Windows下....
06/19 11:18, 8F

06/19 11:19, , 9F
#include "glut.h" 和 #include "GLUT.h" 應該一樣吧??
06/19 11:19, 9F

06/19 11:19, , 10F
不過關鍵是Window下檔名大小寫可識別但視為同樣的....
06/19 11:19, 10F

06/19 11:19, , 11F
所以可能z大才說不曉得Unix-Like系統會怎樣@_@"
06/19 11:19, 11F

06/19 11:25, , 12F
對,指檔名。剛看覺得奇怪怎麼會有a.h跟A.h
06/19 11:25, 12F

06/19 12:13, , 13F
unix-like linux 有分
06/19 12:13, 13F

06/19 12:31, , 14F
每個.h 第一行打 #pragma once
06/19 12:31, 14F

06/19 12:40, , 15F
不要用 #pragma once,這不是標準方法
06/19 12:40, 15F
文章代碼(AID): #1AEjtYow (C_and_CPP)