Linux?????????
???????????? ???????[ 2013/3/28 11:24:36 ] ????????
??????????
????????Windows???е????????Linux???????????????????????????á?Windows???*.dll????Linux???*.so???????????????δ????????Linux??????
?????????????????
??????mytestso.c????У????????£?
#include < stdio.h >
#include < stdlib.h >
int GetMax(int a?? int b)
{
if (a >= b)
return a;
return b;
}
int GetInt(char* psztxt)
{
if (0 == psztxt)
return -1;
return atoi(psztxt);
}
????????????????????б???
gcc -fpic -shared mytestso.c -o mytestso.so
??-fpic ?????????????????????λ???????????
?????????????????????mytestso.so??????????????????mytestso.so??
??????????ù????
??????????е???????????????????У???????????????????????????????С?????????ù?????е??????????????????????????????????????????????????????????ú??????????????????????????????ú?????????ú?????
??????mytest.c????У????????£?
#include < dlfcn.h >
#include < stdio.h >
int main(int argc?? char* argv[])
{
void* pdlhandle;
char* pszerror;
int (*GetMax)(int a?? int b);
int (*GetInt)(char* psztxt);
int a?? b;
char* psztxt = "1024";
// open mytestso.so
pdlhandle = dlopen("./mytestso.so"?? RTLD_LAZY);
pszerror = dlerror();
if (0 != pszerror) {
printf("%s
"?? pszerror);
exit(1);
}
// get GetMax func
GetMax = dlsym(pdlhandle?? "GetMax");
pszerror = dlerror();
if (0 != pszerror) {
printf("%s
"?? pszerror);
exit(1);
}
// get GetInt func
GetInt = dlsym(pdlhandle?? "GetInt");
pszerror = dlerror();
if (0 != pszerror) {
printf("%s
"?? pszerror);
exit(1);
}
// call fun
a = 200;
b = 600;
printf("max=%d
"?? GetMax(a?? b));
printf("txt=%d
"?? GetInt(psztxt));
// close mytestso.so
dlclose(pdlhandle);
}
??????
???·???
??????????????????
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