Eu fiz um gerenciador de memória simples e estou tentando compilá-lo usando a biblioteca compartilhada no driver.
Os próprios arquivos da biblioteca compartilhada são compilados corretamente. No entanto, quando compilei o driver chamando as funções na biblioteca compartilhada com o gerenciador de memória, ele mostra a captura de tela abaixo:
Aquiestáomeucódigoparaoshared.c
/*conveniencesforcastinganddeclarations*/typedefblock_info*(*MM_CREATE)(size_t,MMPolicy);typedefvoid*(*MM_ALLOCATE)(block_info*,size_t,char*);typedefint(*MM_DEALLOCATE)(block_info*,void*);typedefvoid(*MM_DESTROY)(block_info*);/*Functionpointersretrievedfromthesharedlibrary*/typedefstructLibraryFunctions{MM_CREATEcreate;MM_DESTROYdestroy;MM_ALLOCATEallocate;MM_DEALLOCATEdeallocate;}LibraryFunctions;/*Loadsasharedlibraryandreturnsapointertoitinlibhandle*//*ReturnsSUCCESS,ifitsuccessful,otherwise,FAILURE*/intload_library(constchar*libname,void**libhandle){*libhandle=dlopen(*libhandle,RTLD_LAZY);if(!(*libhandle)){returnFAILURE;}else{returnSUCCESS;}return*libname;}intget_functions(void*libhandle,LibraryFunctions*functions,constchar**fn_names){functions->create=(MM_CREATE)(intptr_t)dlsym(libhandle,*fn_names);if(!functions->create){returnFAILURE;}functions->destroy=(MM_DESTROY)(intptr_t)dlsym(libhandle,*fn_names);if(!functions->destroy){returnFAILURE;}functions->allocate=(MM_ALLOCATE)(intptr_t)dlsym(libhandle,*fn_names);if(!functions->allocate){returnFAILURE;}functions->deallocate=(MM_DEALLOCATE)(intptr_t)dlsym(libhandle,*fn_names);if(!functions->deallocate){returnFAILURE;}returnSUCCESS;
Aquifazpartedocódigododriverparachamarabibliotecacompartilhada:
voidsetup(void){constchar*fn_names[]={"mm_create", "mm_destroy", "mm_allocate", "mm_deallocate"};
LibraryFunctions funs;
int error;
error = load_library("./libmemmgr.so", &gLib);
if (error == FAILURE)
{
printf("load_library failed! %s\n", dlerror());
exit(-1);
}
error = get_functions(gLib, &funs, fn_names);
if (error == FAILURE)
{
printf("get_functions failed! %s\n", dlerror());
exit(-1);
}
mmlib_create = funs.create;
mmlib_destroy = funs.destroy;
mmlib_allocate = funs.allocate;
mmlib_deallocate = funs.deallocate;
}
void teardown(void)
{
dlclose(gLib);
}
Não sei o que está causando os erros.
edit: Então eu consegui rodar o arquivo exe, mas falhei em "get_functions". Existe algum problema com minhas funções get_?