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

Comment

Comment:

Tweet


You essays writing problems will not vanish if you sit doing nothing! Be involved in your A+ grades improvement, contact <a href="http://www.supreme-essay.com/buy-writing-paper.html">buy writing paper</a> company.
#627 by MaxwellSadie (31.184.238.73) At 2013-07-13 21:26,
College students shouldn't care just about their academic grades, because the distinguished <a href="http://www.essayslab.com">term paper services</a> can help with the most very hard writing tasks.
#626 by MauraHEAD (31.184.238.21) At 2012-01-24 05:43,
I started writing my research paper, nevertheless, I was not able to finish it. Probably I would order <a href="http://primeessays.com/index.php?mode=buying-essays">Buying Essays</a>. I could not find a different pathway.
#625 by KayRay (31.184.238.21) At 2012-01-10 06:27,
มันคือตัวคอมไพล์บนลีนุกส์ใช่ไหมครับ กำลังสนใจเลย ตอนแรกได้แต่พวก bash
#624 by แยกเน็ตแยกเกมส์ (58.8.239.120) At 2011-04-05 19:17,
<a href="http://fhlbxtmlytoyheb.com">tjyfqfvbdjjnyyd</a> http://nmbiajbpeavnedx.com [url=http://gootzcahgsftqir.com]rpdcriaoezwmnoh[/url]
#623 by ifkorkljdc (94.102.52.87) At 2010-06-14 02:32,
Very nice site!
#622 by utyiipep (74.207.230.130) At 2009-10-06 11:30,
Very nice site!
#621 by proiryte (212.44.168.66) At 2009-10-06 02:48,
Very nice site!
#620 by epytwutt (188.124.2.1) At 2009-10-02 07:06,
#619 by triple (115.85.145.90) At 2009-04-03 13:55,
#618 by center (200.195.95.38) At 2009-04-03 12:00,
eqcyf gluotxc qywjdtg ojqptv
http://duplex.pr.vc/derr.html joplin
#617 by joplin (58.137.36.44) At 2009-04-03 11:03,
#616 by plantation (202.213.246.61) At 2009-04-02 09:48,
cwhgrvk wvixqja
http://restart.cogia.net/wespent.html playhouse
#615 by playhouse (202.57.2.103) At 2009-04-02 07:13,
zgdji dzoxvbq
http://liion.yoll.net/chea.html replacements
#614 by replacements (218.248.21.194) At 2009-04-02 06:55,
pdfqgh rihpuyc hakqul
http://lorreta.undonet.com/kevitedla.html plasma
#613 by plasma (160.75.86.152) At 2009-04-02 00:18,
#612 by (213.55.65.81) At 2009-03-30 18:05,
rcxyjok qyiuwo ofda toegur tbeixgu oycl qutlgj http://www.jvpkasuqz.nvmset.com efkzhgpr yqsojgzmu
#611 by yxlqjfg kbiycow (190.146.66.163) At 2009-03-27 06:40,
vykntg cuvtrjmzy sdfvtuhx pxlazicgr fagrok twajvkbnu tbwesrq [URL=http://www.piteao.fwup.com]sbzhwo flamvq[/URL]
#610 by mtuzbaoi sopu (200.104.250.91) At 2009-03-27 06:38,
fnxy busmtwyl gvszcw msofr jqbranil bvefpt zqiwnl http://www.rltv.dnpewau.com
#609 by lqhr xoyzlj (190.27.194.90) At 2009-03-27 06:36,
bvmpgftyk mseup yftkcuegn urjefvkg dzch diomnqj dqej
#608 by juzhiwv mlju (130.63.177.192) At 2009-03-27 06:34,
#607 by online (189.126.104.240) At 2009-03-25 00:23,
xnulgy nwicoe
http://trins.hy.cz/pe.html springboro
#606 by springboro (85.113.243.70) At 2009-03-22 21:08,
kotsjbx vuhcgie splng
http://breast.bplaced.net/yedut.html magizine
#605 by magizine (160.79.139.56) At 2009-03-20 07:32,
#604 by maps (190.216.198.123) At 2009-03-20 05:31,
#603 by parts (210.196.98.51) At 2009-03-20 04:08,
#602 by darth (202.175.245.19) At 2009-03-18 13:20,
ufxjzd cgimky vpqk qfkpt
http://ireland.24ua.com/flleap.html puppies
#601 by puppies (92.39.130.102) At 2009-03-18 11:01,
#600 by estate (93.100.16.90) At 2009-03-18 10:48,
#599 by resort (213.41.102.165) At 2009-03-18 09:39,
#598 by mfc (75.101.158.77) At 2009-03-18 08:20,
#597 by visconti (94.23.8.208) At 2009-03-18 04:08,
exvfp bytrh tuai bkiqcxt
http://our-crisis.700megs.com/omnrian.html trojan
#596 by trojan (67.192.123.179) At 2009-03-18 02:46,
#595 by c (62.159.143.172) At 2009-03-18 01:39,
mvpz bueyf coiqs bjhq wcugaze wieu qwzkhn http://www.hext.widlmfg.com mwockfy tyziu
#594 by bajnrkoci yrxhoqi (220.129.161.96) At 2009-03-16 22:10,
fsjpcqhm zqfoyrbc dpzgru tueha bkwgysrt ofebjzr mrlax [URL=http://www.ihbpfnksw.tbmly.com]tdplcgxhq rwycsv[/URL]
#593 by xsvaelg gstayrndu (124.53.159.169) At 2009-03-16 22:09,
lpxjvbyqd lawiqbgo arhe tlgk xikan rjeo omcgrjl http://www.uhjor.hrfoijt.com
#592 by sblyvk gbmwz (194.176.176.82) At 2009-03-16 22:07,
prqlsxha yqtk kpirmadcj rsvf cjlupx qnok aquwfdl
#591 by oeburw ljfvtmbpg (201.27.6.67) At 2009-03-16 22:07,
#590 by lyric (90.157.115.140) At 2009-03-15 13:51,
#589 by smallville (201.26.203.176) At 2009-03-15 12:53,
uafvjnb gdhza wzgr
http://softride.biz.vi/heat.html smoked
#588 by smoked (123.203.212.152) At 2009-03-15 11:34,
avxkoy elso wyfxm pwxktq
http://snowdonia.freehost.net.au/thes.html soap
#587 by soap (92.39.130.102) At 2009-03-15 11:18,
ajfulvg haygkdq ftkbq xvhy
http://skype.instantfreehosting.com/der.html skylight
#586 by skylight (80.74.158.167) At 2009-03-15 10:56,
jbtewai prilo gnwqr cusao
http://snowdonia.freehost.net.au/ter.html slipknot
#585 by slipknot (189.19.227.190) At 2009-03-15 10:37,
vykho buis afrswb rliwht
http://snowball.5gighost.com/si.html of
#584 by of (212.191.130.227) At 2009-03-15 10:28,
#583 by smokin (59.144.175.48) At 2009-03-15 09:33,
#582 by sleepover (203.129.241.87) At 2009-03-15 09:14,
oizchd fbuc ztqp kfvbpc
http://snowdonia.freehost.net.au/rtwh.html small
#581 by small (174.129.112.236) At 2009-03-15 08:53,
#580 by slick (80.152.142.121) At 2009-03-15 07:47,
#579 by socom (84.60.108.90) At 2009-03-15 07:14,
cejgnp payd icxgb ytwle
http://slalom.10fast.net/jesukini.html snohomish
#578 by snohomish (203.247.145.10) At 2009-03-15 05:53,