Thực hành Objective C với GNUStep trên ubuntu
đầu tiên bạn cài đặt các gói sau để lập trình:
Linux Shell Code:
sudo apt-get -y install build-essential sudo apt-get -y install gnustep sudo apt-get install gobjc sudo apt-get install gnustep-make sudo apt-get install libgnustep-base-dev
gõ lệnh
thêm vào cuối file dòng sausudo gedit /etc/profile
sau đó khởi động lại máy ubuntu để nhận biến môi trườngexport GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefiles
1) bài thực hành lập trình C thuần với trình biên dịch objective C GNUstep
tạo file main.c
C Code:
#include <stdio.h> int main(void) { }
tạo GNUmakefile với nội dung như sau:
GNU Make Code:
include $(GNUSTEP_MAKEFILES)/common.make CTOOL_NAME = HelloWorld HelloWorld_HEADERS = HelloWorld_C_FILES = main.c HelloWorld_RESOURCE_FILES = include $(GNUSTEP_MAKEFILES)/ctool.make
đặt vào cùng thư mục và gõ lệnh make
gõ lệnhđể in ra kết quả màn hình./shared_obj/HelloWorld
Bài 2) viết 1 chương trình thuần C sử dụng C posix trên MACOS
main.c
C Code:
#include <stdio.h> #include <stdlib.h> #include <pthread.h> void *Day_la_Thread_Ma_Ban_CanDung( void *ptr ) { char *message; message = (char *) ptr; } int main() { pthread_t thread1, thread2; char *message1 = "Sonnh89: Day la Thread 1"; char *message2 = "Sonnh89: Day la Thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, Day_la_Thread_Ma_Ban_CanDung, (void*) message1); iret2 = pthread_create( &thread2, NULL, Day_la_Thread_Ma_Ban_CanDung, (void*) message2); pthread_join( thread1, NULL);//day la ham wait cho thread thuc hien xong moi chay tiep pthread_join( thread2, NULL); return 0; }
gnumakefile
GNU Make Code:
include $(GNUSTEP_MAKEFILES)/common.make CTOOL_NAME = HelloWorld HelloWorld_HEADERS = HelloWorld_C_FILES = main.c HelloWorld_RESOURCE_FILES = [B][COLOR="Red"]ADDITIONAL_TOOL_LIBS += -pthread[/COLOR][/B] include $(GNUSTEP_MAKEFILES)/ctool.make