shared library 筆記
source: http://www.thegeekstuff.com/2012/06/linux-shared-libraries/ 無聊來練一下shared library好了。 1.先寫好share.c #include "shared.h" unsigned int add(unsigned int a, unsigned int b) { printf("\n Inside add()\n"); return (a+b); } 2.share.h #include extern unsigned int add(unsigned int a, unsigned int b); 3.編釋囉 gcc -c -Wall -Werror -fPIC share.c gcc -shared -o libshare.so share.o 4.產生出來libshare.so囉!!! # ls libshare.so share.c share.h share.o 5.寫一個測式的程式 include #include"share.h" int main(void) { unsigned int a = 1; unsigned int b = 2; unsigned int result = 0; result = add(a,b); printf("\n The result is [%u]\n",result); return 0; } # gcc -L. -Wall sharetest.c -o go -lshare -L. 在當前的目錄下,找-lshare 名稱為libshare.so的library來編。 # go ./go: error while loading shared libraries: libshare.so: cannot open shared object file: No such file or directory go的測試程式找不到需要的...