Search in Devinthailand

Friday 30 July 2010

Macports installไม่ได้ แก้ยังไงดี

วันนี้ผมจะเขียนโปรแกรมโดยใช้ perl เรียกใช้ cURL แต่ดันไม่มี
เลยต้อง install macports ซะหน่อย
ก็ไปดาวน์โหลดfile install แบบ wizard มา
แต่พอลงแล้ว
sudo port --version
dlopen(/opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib, 10): no suitable image found.  Did find:
    /opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib: mach-o, but wrong architecture
    while executing
"load /opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib"
    ("package ifneeded Pextlib 1.0" script)
    invoked from within
"package require Pextlib 1.0"
    (file "/opt/local/bin/port" line 40)
เรียกใช้งานไม่ได้
เลยต้องลงใหม่
เปิดเข้า terminal เลยครับ จากนั้นพิมพ์ sudo su root ใส่ password ให้เรียบร้อย
หาที่ไว้สำหรับ download ไฟล์จาก svn ส่วนผมเลือก /Users/xxx/
จากนั้นพิมพ์
svn co http://svn.macports.org/repository/macports/trunk/base/ macports-svn
รอซักครู่
เมื่อดาวน์โหลดเสร็จ ก็เข้าไป folder macports-svn
ด้วยคำสั่ง cd macports-svn
แล้วตามด้วย ./configure && make && make install;
รอซักพัก
เมื่อเสร็จแล้ว ก็ sync ข้อมูลจาก server ด้วยคำสั่ง sudo port -d sync

เมื่อเสร็จแล้ว จะขึ้นประมาณนี้
sent 312205 bytes  received 11092961 bytes  57747.68 bytes/sec
total size is 26320418  speedup is 2.31
DEBUG: /usr/bin/rsync -rtzv --delete-after rsync://rsync.macports.org/release/ports/PortIndex_darwin_10_i386/PortIndex /opt/local/var/macports/sources/rsync.macports.org/release/ports
receiving file list ... done
PortIndex

sent 58 bytes  received 938694 bytes  34136.44 bytes/sec
total size is 4036551  speedup is 4.30
Creating port index in /opt/local/var/macports/sources/rsync.macports.org/release/ports

Total number of ports parsed:    0
Ports successfully parsed:    0
Ports failed:            0
Up-to-date ports skipped:    7257

เป็นอันว่าเสร็จส่วนจะ install อะไรเพิ่มก็เลือกจาก
http://perl.darwinports.com/ นะครับ
ส่วนผมก็ จัด cURL ด้วยคำสั่ง sudo port install curl
รอซักพักก็เป็นอันว่าเสร็จ

เริ่มต้น Objective C part 1

Objective C 
Objective C พัฒนาต่อมาจาก ภาษา C
ส่วน Cocoa ก็เป็น Framework ของ Objective-c ซึ่ง apple นำมาใช้ develop application ต่างๆนานา
โดยส่วนใหญ่การเขียนโปรแกรม จะใช้ IDE ที่มีชื่อว่า Xcode ของ Apple เองด้วย
ส่วนตัวผม ผมคิดว่ามันเป็น IDE ที่เยี่ยมยอดตัวนึงเลยแหละ
ง่ายในการใช้มาก http://developer.apple.com/ สมัครแล้วเข้าไปโหลดได้เลย

มาเริ่มรู้จัก Objective C กันที่ Data Types
1) Int Data Type
int มาจากคำว่า Integer แปลว่า จำนวนเต็ม ดังนั้น int คือการเก็บจำนานเต็มนะไม่มีจุดทศนิยม
โดยจะเก็บอย่างน้อย16 bits

 การประกาศตัวแปร int ก็เช่น int myint = 10;
 2) char Data Type คือ ชนิดตัวแปรที่เก็บเสียงตัวอักษรตัวเดียว เช่น เก็บเพียงตัว C ตัวเดียว
การใช้งานก็เช่น
char a = 'a';
char w = 'w';
char colon = ':';
Char ก็ไม่ได้มีแค่นี้นะ ยังมี Special Character อีกเช่น
char newline = '\n';
ถ้าจะใส่ Backslash ล่ะ ก็แบบนี้ char mybackslash = '\\';
ยังมีอีกนะ
\a - Sound alert
\b - Backspace
\f - Form feed
\n - New line
\r - Carriage return
\t - Horizontal tab
\v - Vertical tab
\\ - Backslash
\" - Double quote
\' - Single quote
บางตัวก็ยังไม่เคยใช้แหะๆ

3) Float Data Type คือชนิดตัวแปรที่เก็บเลขทศนิยมนั่นเอง 32bit
ตัวอย่างเลขก็เช่น  123.45 , 543.21 เป็นต้น
การใช้งานง่ายมากครับ
float a = 111.22f;
f  ต่อท้ายก็หมายถึงกำหนดว่าเป็น ชนิด float นะครับ
float expfloat = 10.22e4;
ตัว e ต่อท้ายมาจาก exponential ครับ ค่าfloatจะได้เป็น 10.22 x 10^4 เป็นต้น
4) Double Data Type ก็ลักษณะเดียวกับ Floatแหละครับเก็บเลขทศนิยมเหมือนกัน แต่สามารถเก็บเลขที่มีขนาดใหญ่ได้มากกว่า float
5) Boolean คือตัวแปรที่เก็บ true หรือ false
โดยค่าจะมีเพียง2 ค่า เท่าคือ 1 และ 0
1 คือ true
2 คือ false
ส่วนการประกาศใช้งานนั้น ประกาศได้สองรูปแบบ คือ 1) _Bool flagOne = 1;
หรือ 2) BOOL testFlag = 0;

คราวนี้มาดู qualifier กันบ้าง
Qualifier หมายถึงอะไร แปรตามตัวครับ คือ "ตัวขยาย"
long คือการขยายการเก็บขนาดของตัวแปรไปอีกหนึ่งเท่า
เช่น  int a; จะเก็บในขนาด 16bits
แต่ long int a; จะเก็บในขนาด 32bits
และ long long int a; ละ ก็ เก็บในขนาด 64bitsนั่นเอง
ส่วน short จะเก็บขนาดเท่าเดิมแต่จะใช้ memory ครึ่งนึงของปกติ
เช่น short int a; ก็จะเก็บอย่างน้อย 16bits แต่จะใช้ memory ในการเก็บครึ่งนึงของ int a;

signed และ unsigned คืออะไร
signed จะสามารถเก็บตัวเลข ที่มีเครื่องหมายข้างหน้าได้
unsigned ก็ตรงข้ามกันครับ เก็บแบบไม่มีเครื่องหมายข้างหน้า

unsigned int ของComputer 32 bits จะเริ่มจาก 0 ถึง 4294967295 และ 64 bits จะเริ่มจาก 0 ถึง 18,446,744,073,709,551,615
signed int value ของComputer  32 bits จะเริ่มจาก  −2,147,483,648 ถึง +2,147,483,647 และ 64 bits จะเริ่มจาก  −9,223,372,036,854,775,808 ถึง +9,223,372,036,854,775,8

การใช้งานก็เช่น unsigned int myint;
signed int myint2;

ถ้าผิดพลาดประการใดก็ขอโทษด้วยนะครับ