parent
2dd7f3cb47
commit
49e0676ba9
4 changed files with 65 additions and 4 deletions
@ -1,4 +1,8 @@ |
||||
project('shared module', 'c') |
||||
|
||||
shared_module('mymodule', 'module.c') |
||||
dl = meson.get_compiler('c').find_library('dl', required : false) |
||||
l = shared_library('runtime', 'runtime.c') |
||||
m = shared_module('mymodule', 'module.c') |
||||
e = executable('prog', 'prog.c', link_with : l, dependencies : dl) |
||||
test('import test', e, args : [m.full_path()]) |
||||
|
||||
|
@ -0,0 +1,38 @@ |
||||
#ifdef _WIN32 |
||||
// FIXME: add implementation using Winapi functions for dlopen.
|
||||
|
||||
int main(int argc, char **argv) { |
||||
return 0; |
||||
} |
||||
|
||||
#else |
||||
|
||||
#include<dlfcn.h> |
||||
#include<assert.h> |
||||
#include<stdio.h> |
||||
|
||||
int func(); |
||||
int func_from_language_runtime(); |
||||
|
||||
int main(int argc, char **argv) { |
||||
void *dl; |
||||
int (*importedfunc)(); |
||||
int success; |
||||
char *error; |
||||
|
||||
dlerror(); |
||||
dl = dlopen(argv[1], RTLD_LAZY); |
||||
error = dlerror(); |
||||
if(error) { |
||||
printf("Could not open %s: %s\n", argv[1], error); |
||||
return 1; |
||||
} |
||||
importedfunc = (int (*)()) dlsym(dl, "func"); |
||||
assert(importedfunc); |
||||
assert(importedfunc != func_from_language_runtime); |
||||
success = (*importedfunc)() == func_from_language_runtime(); |
||||
dlclose(dl); |
||||
return !success; |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,19 @@ |
||||
#if defined _WIN32 || defined __CYGWIN__ |
||||
#define DLL_PUBLIC __declspec(dllexport) |
||||
#else |
||||
#if defined __GNUC__ |
||||
#define DLL_PUBLIC __attribute__ ((visibility("default"))) |
||||
#else |
||||
#pragma message ("Compiler does not support symbol visibility.") |
||||
#define DLL_PUBLIC |
||||
#endif |
||||
#endif |
||||
|
||||
/*
|
||||
* This file pretends to be a language runtime that supports extension |
||||
* modules. |
||||
*/ |
||||
|
||||
int func_from_language_runtime() { |
||||
return 86; |
||||
} |
Loading…
Reference in new issue