gcc 不能過 - Linux

Table of Contents

※ 引述《bluehaerts (5858笨58)》之銘言:
: 請問各位高手:
: 我在 vi 裡面編輯一個簡單讀取 字元 的c程式
: 可是 編譯之後 他沒有 #include<conio.h> 這個標題檔
: 所以我 getch() 不能用
: 請問 我再gcc 的時候 要加入哪個參數
: 我知道 include<math.h>
: 是在 gcc 檔名.c -lm
: 可是........我不知道 #include<conio.h>
: 這個要加啥 google 也是不知道 要查啥關鍵字
: 請問 各位高手 可以提示一下嘛
: 補一下他的訊息
: /tmp/ccAF0Xdk.o(.text+0x67): In function `main':
: : undefined reference to `getch'
: collect2: ld returned 1 exit status

首先要知道你要 include 的 header file 放在哪裡
也就是 conio.h 放在哪

假設它在 /usr/local/include/bluehaerts 裡面
在 gcc 編譯的時候就把這個路徑加入到搜尋路徑裡面

gcc 檔名.c -lm -I/usr/local/include/bluehaerts


--


隨手關電腦,救救北極熊


--

All Comments

Lily avatarLily2009-03-26
可是 是學校主機 我可以 用啥指令查到嘛
John avatarJohn2009-03-26
他放在哪個位子嘛
Brianna avatarBrianna2009-03-30
還有 我們學校主機 只要打 檔名.C -lm
就可以編譯了耶 不用 加後面那串說
Brianna avatarBrianna2009-03-31
因為 math.h 是放在 gcc 預設就會去找的地方,所以不用加 -I
Skylar DavisLinda avatarSkylar DavisLinda2009-04-05
這種編譯選項就能編譯了。
Puput avatarPuput2009-04-09
另外補充一點,header file 和 library file 是兩回事,加了
Victoria avatarVictoria2009-04-12
-I<header 路徑> 通常也必須另外再加 -L<library 路徑> 才能
John avatarJohn2009-04-14
成功編譯。