From 82b1cce1bc5c91c0b56501f5dab912390206ace5 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Thu, 20 Jun 2024 20:39:08 +0900 Subject: Use cli and gui as shared libraries --- src/disp.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/disp.c') diff --git a/src/disp.c b/src/disp.c index 6710f40..27f74e4 100644 --- a/src/disp.c +++ b/src/disp.c @@ -24,12 +24,14 @@ #include "disp.h" -#define dlsym_and_check(dest, name) \ - dest->name = dlsym(dest->dl_handle, #name); \ - if (!dest->name) { \ - dlclose(dest->dl_handle); \ - free(dest); \ - return NULL; \ +#define dlsym_and_check(dest, name) \ + dest->name = dlsym(dest->dl_handle, #name); \ + if ((!dest->name) || (dest->name == dest->dl_handle)) { \ + char *msg = dlerror(); \ + fprintf(stderr, "calculer: %s\n", msg); \ + dlclose(dest->dl_handle); \ + free(dest); \ + return NULL; \ } struct disp * @@ -37,10 +39,10 @@ get_disp(char *disp_name) { #ifndef NDEBUG /* displays are shared libraries */ - char so_path[16] = {0}; - strcpy(so_path, "./"); + char so_path[64] = {0}; + strcpy(so_path, "./src/.libs/"); strcat(so_path, disp_name); - strcat(so_path, ".la"); + strcat(so_path, ".so.0.0.0"); void *handle = dlopen(so_path, RTLD_LAZY); if (!handle) @@ -52,6 +54,7 @@ get_disp(char *disp_name) struct disp *disp = malloc(sizeof(*disp)); disp->dl_handle = handle; + dlsym_and_check(disp, init); dlsym_and_check(disp, display_calc); dlsym_and_check(disp, read_input); dlsym_and_check(disp, display_res); -- cgit v1.2.3