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

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

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


就可正常編譯了

posted on 2007-10-20 21:26  真 OO无双  阅读(30888)  评论(4编辑  收藏  举报

导航