Ubuntu 編譯 c程式

2009-04-29 9:49 pm
我的Ubuntu 是 8.0.4版
目前連編譯 helloworld.c 都沒辦法成功 (gcc helloworld.c)
error是說找不到標頭檔

在網路上找了很多方法,
例如:
灌g++, build-essential
sudo apt-get install g++
sudo apt-get install build-essential
不過仍舊沒辦法成功
都說找不到
Couldn't find package build-essential
Couldn't find package g++

(gcc 已是最新版本)

請問是哪裡有問題嗎?
需要怎嚜弄呢?
非常感謝~!!
更新1:

error message shows: test.c: 1: 19: error: stdio.h: No such file or directory test.c: In function 'main' test.c: 5: warning: incompatible implicit declaration of built-in function 'printf'

更新2:

Result after I typed dpkg -l | grep gcc: ii gcc 4:4.2.3-lubuntu3 The GNU C compiler ii gcc-4.2 4.2.3-2ubuntu7 The GNU C compiler (continue..)

更新3:

(continue) ii gcc-4.2-base 4.2.3-2ubuntu7 The GNU Compiler Collection (Base Package) ii libgcc1 1:4.2.3-2ubuntu7 GCC suport library

更新4:

After I try the following instructions through my dorm network sudo apt-get install g++ sudo apt-get install build-essential finally i can compile and run helloworld.c However i still worry about that i saw many updates failed, don't know if it'll cause problems...?

回答 (3)

2009-04-30 3:00 pm
✔ 最佳答案
Have gcc and other build-essentials been installed? What is your program's code? The error suggests problem with your header file.

2009-04-29 23:12:34 補充:
Has your machine connected to the internet? The error from apt-get suggests the program cannot find the packages. Did you install packages from CD or the internet?

2009-04-30 07:00:50 補充:
The following should work on all *nix platforms:

#include <stdio.h>
int main()
{
printf("hello world\n");
}

/* if this fails, give me the error message */
======================================
Also, for your Ubuntu installation, apt-get will try to get the package from the installation medium (whatever that maybe). In your case, it is the CD your friend install that from. I think you will have to change that to the network before it will work. You can ask the one who installs this for you for help.

To check if gcc is installed on your machine:

dpkg -l | grep gcc

This command will give a few lines of output. That should include gcc, libgcc and gcc base.

You don't need g++ nor the build-essential for the hello world program. If you are just learning this, you don't need all the tools yet.



2009-05-01 06:18:39 補充:
It is possible to have update failed. It happens to me all the time with Ubuntu :-(

You can investigate it more. However, sometimes, it is the packaging method that causes the problem. It may point to some files that does not exist.

2009-05-01 06:19:51 補充:
As a new comer, I think you should stick with just C (or C++ or Java) and some simple Linux commands for now. Knowledge will come to you later.
2014-10-02 7:30 pm
您期待已久的 8891遊樂城 熱烈開幕囉!

8891遊樂網以優質的服務領先業界

多位美女客服24小時即時線上為您服務!

8891遊戲城有優於市面所有運動投注遊戲的 賠 ~ 率

以及免下載美女 百家樂、21點、骰寶、各國賓果、餐廳賓果、彩球遊戲

另有數百位真人視訊聊天辣妹與您進行互動聊天還有"精彩"電影喔!

心動了嗎!! 快來體驗市面上最完質最高品質的服務

現在有開放免費試玩喔! 官網 : 8891.NET
2009-04-30 8:25 am
-I don't know..I never use Linux before. don't know anything about it..
but i am sure that gcc can work, just can find the header file (i can't find
those header files in 'include' folder)

2009-04-30 00:25:38 補充:
- program
#include
int main(void){
printf("HelloWorld");
return 0;
}
=>error message shows that cannot find stdio.h

2009-04-30 00:28:39 補充:
-Yes, but connected to wireless network
I tried several suggestions that i googled, I found out some updates very slowly and finally faild, I'll try not use wireless network tomorrow and try it again

-my friend installed it for me, probably from CD but not very sure..

thanks!


收錄日期: 2021-04-29 22:18:15
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090429000010KK04308

檢視 Wayback Machine 備份