顯示具有 c 標籤的文章。 顯示所有文章
顯示具有 c 標籤的文章。 顯示所有文章

2015年10月13日 星期二

Linux C program tips

compile object files gcc -c 1.c --> automatically generate 1.o file link object files and generate binary file gcc -o app 1.o 2.o main.o build archives -- static library ar cr libkido.a 1.o 2.o main.o gcc -L . -lkido -o app build shared library gcc -c -fPIC 1.c --> automatically generate 1.o file gcc -shared -fPIC -o libkido.so main.o 1.o 2.o gcc -o app -L . -lkido -Wl,-rpath,./ <-- if rpath is not defined, LD_LIBRARY_PATH need to be defined in environment variable to have the binary locate library file

2014年12月8日 星期一

struct mapping

__attribute__((packed)); need to be added otherwise it may cause memory alignment issue #include #include #include #include #include #include #include #include #include #include #include struct test { uint8_t sig[4]; uint8_t len; uint8_t mic_sig[5]; uint32_t vid; uint16_t did; uint16_t idxx; } __attribute__((packed)); int main(){ uint8_t test_string[]={'K','I','D','O',0x40,'M','i','T','A','C',0x86,0x80,0x02,0x3c,0x86,0x81,0x01,0x3c}; struct test *info=(struct test *)test_string; printf("sig=%.4s len=0x%x mic_sig=%.5s vid=0x%04x did=0x%04x idxx=0x%04x\n" ,info->sig, info->len, info->mic_sig, info->vid, info->did, info->idxx); return 0; }