2015年6月14日 星期日

Compile QEMU in ubuntu 14.04

To compile QEMU in ubuntu 14.04, you need to download the needed libraries first
sudo apt-get install zlib1g-dev libglib2.0-dev autoconf automake libtool
If you need to browse the execution screen via a window in host instead of using VNC, you will need to install gtk.
sudo apt-get install build-essential libgtk2.0-dev libvte-dev
Then command ./configure --target-list="What you desire" --enable-gtk.
ex: ./configure --target-list="x86_64-softmmu" --enable-gtk
Then command make, and it will make the files in some directory, ex:"x86_64-softmmmu".
Btw, you can use -j8 to accelerate with 8 threads,' there is no space between 'j' and8', unlike compiling linux kernel.

pthread

除了要#include <pthread.h>
編譯的時候還要下-pthread指令
ex:gcc test.c -o test -pthread

pthread_create(pid,NULL,*void,(*void)arg);
第三項是pthread要跑的function位置,這個function只能接受一個argument傳入,限定為void type,有需求傳入多個arguments時,定一個struct把需要的arguments都包起來。可以回傳值,所以也限定為void*,因此function定義時要定成void* mydeffunc(void* arg)

ex:


void *doit(void *arg);

/*define a struct to wrap needed arguments*/
struct myDefStruct
{
struct sockaddr_in servaddr;
int sockfd;
};

/*call pthread_create的時候*/
/*when call pthread_create*/
struct myDefStruct *myDefPtr;
for ( ; ; ) {
clilen = sizeof(cliaddr);
connfd = accept(listenfd, (__SOCKADDR_ARG) &cliaddr, &clilen);
myDefPtr= (struct myDefStruct*)malloc(sizeof(struct myDefStruct));
myDefPtr->servaddr = cliaddr;
myDefPtr->sockfd = connfd;
pthread_create(&tid, NULL, &doit, (void*)myDefPtr);
 }


/*如何取出void*型別的資訊*/
/*How to retrieve the data in void* type by casting*/
void *doit(void *arg)
{
int sockfd = ((struct myDefStruct*)arg)->sockfd;
struct sockaddr_in servaddr = ((struct myDefStruct*)arg)->servaddr;
...............
}

用gcc編譯c++的檔案

要加-lstdc++指令
ex:gcc test.cc -lstdc++ -o test

unix下include math.h、cmath

在compile的時候要加上-lm的指令
ex: gcc test.c -o test -lm