2009年11月4日

如何在Ubuntu上編譯C語言程式碼? (C/C++) (C) (Linux) (Ubuntu)

Ubuntu上雖然已經內建gcc,不過卻沒內建最基本的Standard C Library,要如何在Ubuntu下編譯C語言程式碼呢?

引用:
http://www.cnblogs.com/oomusou/archive/ ... 31707.html

Introduction


一個最簡單的C語言Hello World

#include <stdio.h>

int main() {
  printf(
"%s","Hello World!!");
}


在Ubuntu的console下打
gcc hello_world.c

會出現
hello_world.c:1:19: error: stdio.h: No such file or directory
hello_world.c: In function ‘main’:
hello_world.c:
4: warning: incompatible implicit declaration of built-in function ‘printf’

表示連最基本的stdio.h都找不到


sudo find / -name stdio.h

找遍整個硬碟,果然找不到stdio.h

Solution
下載g++
sudo apt-get install g++

Ubuntu就會自動安裝g++
裝完之後,stdio.h會在/usr/include/下找到

之後再
gcc hello_world.c

就可正常編譯了


有網友提議:
sudo apt-get install build-essential
所抓下來的library比較完整,有在ubuntu中下載過了,而且也可以順利編譯c語言了,就沒深入研究下去了.

沒有留言:

張貼留言

NO-CARRIER 網卡無法啟動

 工作時,由於想要啟動linux OS的網卡, 發現某張新設定的網卡一直無法啟動,就算下指令UP了,但是也沒有順利啟動 所以爬文後,想要確認該網卡的status, 發現某行為: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu...