Linux????????????·?????
???????????? ???????[ 2015/11/25 13:34:01 ] ??????????????
?????????*.so??linux????c??c++?????????????á?
????1???????????
??????????????????????????????????????????????????????so_test.h??????.c?????test_a.c??test_b.c??test_c.c???????????????????????????
libtest.so??
------------so_test.h--------------
void test_a();
void test_b();
void test_c();
--------------test_a.c---------------
#include <stdio.h>
#include <stdlib.h>
void test_a()
{
printf("this is in test_a...
");
}
--------------test_b.c---------------
#include <stdio.h>
#include <stdlib.h>
void test_b()
{
printf("this is in test_b...
");
}
---------------test_a.c--------------
#include <stdio.h>
#include <stdlib.h>
void test_c()
{
printf("this is in test_c...
");
}
??????????????????????????libtest.so
????$ gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so
??????????????????????????????5
????2????????????
??????1???У????????????????????????????????libtest.so????????????????????????????????????????????????????test.c??
????---------------test.c---------------
????#include "so_test.h"
????int main()
????{
????test_a();
????test_b();
????test_c();
????return 0;
????}
??????test.c?????libtest.so??????????????test??
????$ gcc test.c -L. -ltest -o test
?????????????????????г?libtest.so????????????????????
????$ ldd test
???????test???????????????ε????????е???????
????3?????????????
???????????GCC?????е???????:
????-shared?????????????????????????????????T??????????????????????????????W???????????????????????????????????????????????????
????-fPIC??????????λ??????????????????????????????????λ????????????????????????????????????????????????????????????????ι????????
????-L.????????????????????
????-ltest???????????????????????????????????????????????????????lib?????????.so????????????
????LD_LIBRARY_PATH????????????export??????????????????????????????????·????????????root??????????????/etc/ld.so.conf??????????? /sbin/ldconfig???????????????????????root?????????????export LD_LIBRARY_PATH??????????????
????4?????
?????????????????м??????????????????????????????????????????? ??? “-I” include??????????????????? “-L”?????????????????“-l”????????????ldd?????????????????????????????so???????????????????????LD_LIBRARY_PATH????/etc/ld.so.conf?????????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11