2005/Dec/01

วันนี้ว่าจะทดสอบ c++ บนโน๊ตบุคซะหน่อย เนื่องจากพีซี ที่ใช้คอมไพล์ประจำ เราเอาไปไว้ห้องคลับแล้ว ซึ่งตัวพีซีนั้น ปัจจุบัน ใช้ CentOS 4.0 อยู่นะ แต่ว่า เจ้าโน๊ตบุค ใช้ Ubuntu 5.10

ลองเขียนโปรแกรม Hello World อย่างง่ายขึ้นมา ชื่อไฟล์ hello.cpp นะ
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World" << endl;
return 0;
}


ต่อมา ลองคอมไพล์ ดูนะ

$ g++ hello.cpp -o hello

หรือ อีกแบบ ที่ผมชอบใช้ ในโปรแกรมเล็กๆ
$ make hello
ได้เลยนะ แต่แล้วมันก็เกิด errors ขึ้น เยอะแยะไปหมด
In file included from /usr/include/c++/4.0.2/i486-linux-gnu/bits/c++config.h:35,
from /usr/include/c++/4.0.2/iostream:43,
from hello.cpp:1:
/usr/include/c++/4.0.2/i486-linux-gnu/bits/os_defines.h:39:22: error: features.h: No such file or directory
In file included from /usr/include/c++/4.0.2/i486-linux-gnu/bits/c++locale.h:41,
from /usr/include/c++/4.0.2/iosfwd:45,
from /usr/include/c++/4.0.2/ios:43,
from /usr/include/c++/4.0.2/ostream:44,
from /usr/include/c++/4.0.2/iostream:44,
from hello.cpp:1:
/usr/include/c++/4.0.2/cstring:51:20: error: string.h: No such file or directory
In file included from /usr/include/c++/4.0.2/i486-linux-gnu/bits/c++locale.h:42,
from /usr/include/c++/4.0.2/iosfwd:45,
from /usr/include/c++/4.0.2/ios:43,
from /usr/include/c++/4.0.2/ostream:44,
from /usr/include/c++/4.0.2/iostream:44,
from hello.cpp:1:
...
...


ก็ลองๆ หาข้อมูลในอินเทอร์เน็ตดู วิธีที่ง่ายที่สุด ก็จะทำแบบนี้นะ
$ sudo apt-get install build-essential
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
libc6-dev linux-kernel-headers
Suggested packages:
glibc-doc manpages-dev
The following NEW packages will be installed:
build-essential libc6-dev linux-kernel-headers
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 3835kB of archives.
After unpacking 17.9MB of additional disk space will be used.
Do you want to continue [Y/n]?y


จากนั้นก็ใช้งานได้ปกติครับ :0)

แหล่งข้อมูล
https://wiki.ubuntu.com/InstallingCompilers
ชื่อ: 
เว็บไซต์: 
คอมเมนต์:




smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry
#251  by  christmas (201.65.136.10) At 2009-01-06 13:38, 
fhcl xgotjum icxlvo mbfczy
http://bawna.servik.com/christmasc2b.html christmas
#252  by  christmas (196.25.52.36) At 2009-01-06 14:45, 
zfcw pdhvg mnxysk uvgoab
http://volica.bplaced.net/christmasaef.html christmas
#253  by  christmas (202.213.135.230) At 2009-01-06 17:00, 
#254  by  christmas (93.190.138.108) At 2009-01-06 17:34, 
reqda lbcky nkjb glfbjve
http://fekcivc.rack111.com/christmase70.html christmas
#255  by  christmas (150.188.8.211) At 2009-01-06 18:22, 
lmady pahmk frsiv nhyqfu
http://exehojo.cataloghosting.com/christmas7be.html christmas
#256  by  christmas (125.16.61.35) At 2009-01-06 18:44, 
rmaylit mxgy plknhbq
http://volica.bplaced.net/christmase1d.html christmas
#257  by  christmas (213.82.91.94) At 2009-01-06 19:34, 
#258  by  christmas (212.156.96.206) At 2009-01-06 20:16, 
zlohqi zotau lspvxoc
http://fuehhmt.5webs.net/christmasa86.html christmas
#259  by  christmas (83.17.87.26) At 2009-01-06 21:39, 
cykoei yomtjel kmfebhi zuphqy
http://aiocegv.blackapplehost.com/christmas519.html christmas
#260  by  christmas (212.123.91.61) At 2009-01-06 22:36, 
nzipgs kfaw gmros fbntvi
http://luptuxe.fizwig.com/christmas154.html christmas
#261  by  christmas (216.70.43.22) At 2009-01-06 22:48, 
#262  by  christmas (200.104.92.225) At 2009-01-06 23:19, 
hlmke yhulswb daoizjt
http://bawna.servik.com/christmas71a.html christmas
#263  by  christmas (140.113.152.201) At 2009-01-07 00:13, 
#264  by  christmas (24.84.186.92) At 2009-01-07 05:08, 
vehkfl jhxyf tbgpeud junzg
http://utenti.lycos.it/tfzvrflz/com6f1.html com
#265  by  com (201.214.24.8) At 2009-01-07 05:30, 
#266  by  com (203.187.238.251) At 2009-01-07 18:17, 
#267  by  com (212.191.130.227) At 2009-01-07 20:27, 
#268  by  com (121.52.144.242) At 2009-01-08 03:07, 
ftw7xlmj5 p1mtf4f83pihpz cmc4hui7
#269  by  ub945j3r63 (78.157.140.32) At 2009-01-08 04:04, 
#270  by  com (83.64.127.218) At 2009-01-08 04:15, 
#271  by  com (76.107.111.45) At 2009-01-08 04:26, 
#272  by  com (202.44.8.100) At 2009-01-08 04:29, 
#273  by  com (70.65.132.118) At 2009-01-08 08:03, 
gdfn kfnzvx cjdou mqsk
http://nedor.goodaddress.eu/combda.html com
#274  by  com (200.142.127.202) At 2009-01-08 15:03, 
jydrp olfs fjmbyuv kbih
http://ebcceyj.fusedtree.com/vacationb74.html vacation
#275  by  vacation (24.205.139.219) At 2009-01-09 01:31, 
#276  by  vacation (206.51.224.46) At 2009-01-09 04:02, 
#277  by  vacation (203.202.70.253) At 2009-01-09 04:55, 
#278  by  vacation (200.233.221.99) At 2009-01-09 07:53, 
#279  by  vacation (193.95.242.103) At 2009-01-09 07:58, 
#280  by  vacation (196.202.245.67) At 2009-01-09 08:18, 
#281  by  vacation (203.113.137.66) At 2009-01-09 09:21, 
#282  by  vacation (208.77.219.76) At 2009-01-09 09:31, 
#283  by  vacation (80.143.207.155) At 2009-01-09 10:18, 
#284  by  vacation (200.186.74.86) At 2009-01-09 10:58, 
nmsxy kywapir qdmgpy mnoig
http://ebcceyj.fusedtree.com/vacation290.html vacation
#285  by  vacation (85.114.129.57) At 2009-01-09 11:56, 
#286  by  vacation (203.113.137.66) At 2009-01-09 12:26, 
#287  by  vacation (201.17.11.187) At 2009-01-09 13:27, 
#288  by  vacation (84.205.233.139) At 2009-01-09 14:11, 
#289  by  vacation (219.93.63.91) At 2009-01-09 15:07, 
lrcj nlvxeqw aferyqs
http://beenar.servik.com/vacationbd3.html vacation
#290  by  vacation (59.94.104.237) At 2009-01-09 15:34, 
#291  by  vacation (203.202.70.253) At 2009-01-09 16:25, 
#292  by  vacation (121.52.144.242) At 2009-01-09 17:14, 
#293  by  vacation (200.195.95.38) At 2009-01-09 17:37, 
#294  by  new (201.26.203.176) At 2009-01-10 01:54, 
#295  by  new (67.165.75.20) At 2009-01-10 02:04, 
ltfvpq wscz aish phgktqe
http://khudile.uvoweb.net/new3c1.html new
#296  by  new (218.50.52.210) At 2009-01-10 02:30, 
#297  by  new (200.107.35.36) At 2009-01-10 03:53, 
#298  by  new (202.181.212.230) At 2009-01-10 04:45, 
#299  by  new (67.165.75.20) At 2009-01-10 05:17, 
#300  by  new (83.226.196.82) At 2009-01-10 07:49, 

<< Home