交叉編譯環境下動態庫的製作與測試
阿新 • • 發佈:2019-01-13
1、製作一個max.c原始檔,內容如下:
int max(int n1, int n2)
{
return ( n1 > n2 ) ? n1 : n2 ;
}
2、製作一個test_max.c原始檔,內容如下:
#include <stdio.h> #include "max.h" int main(int argc, char *argv[]) { int a = 10, b = 100; printf("max is %d!\n", max(a, b)); return 0; }
3、編譯
arm-hisiv500-linux-gcc -fPIC -shared -o libmax.so max.c
生成libmax.so動態庫檔案。
4、arm-hisiv500-linux-gcc test.c -L. -lmax -o test_max
生成ELF檔案。
5、將test_max與libmax.so拷貝至開發板下。libmax.so檔案需要放在開發板/lib目錄下,如果沒有開啟全部許可權最好chmod將其全部許可權開啟。
6、執行ELF檔案。
7、去掉動態庫後的效果,應該無法執行。