dlopen

Get functions names in a shared library programmatically

霸气de小男生 提交于 2019-11-28 07:15:15
问题 Can I get list of all functions names from a shared library (Linux only) programmatically when I am using dl_open() ? I want something like this: std::vector<std::string> list_all_functions(void *dl) { //... what can I do here? } int main() { void * dl = dl_open("./mylib.so", RTLD_NOW); auto functions = list_all_functions(dl); //... dl_close(dl); return 0; } Example library (mylib.so) Header (.h): extern "C" { int sum (int a, int b); } Source (.c): int sum (int a, int b) { return a + b; }

Main Program and Shared Library initializes same static variable in __static_initialization_and_destruction_0

流过昼夜 提交于 2019-11-28 07:03:47
Does anyone know why a library initialized within dlopen() would initialize a static variable owned by the main program. Both the main program and shared library have a copy of the static variable, but for some reason the shared library re-initializes the main program's copy of the static variable and destructs it, causing a segfault when the main program attempts to destruct it. Is this a case of bad name mangling in the symbol table? This is a case where the runtime linker only wants a single active copy of a symbol in a process. If both a shared object and the executable have a copy of the

Is the function 'dlopen()' private API?

限于喜欢 提交于 2019-11-28 06:52:57
I want use function 'dlopen()' to invoke a dynamic library on iOS platform, is the function 'dlopen()' private API? NSProgrammer I've had success using dlopen on iOS for years. In my use case, I use dlopen to load public system frameworks on demand instead of having them loaded on app launch. Works great! [EDIT] - as of iOS 8, extensions and shared frameworks are prohibited from using dlopen , however the application itself can still use dlopen (and is now documented as being supported for not only Apple frameworks, but custom frameworks too). See the Deploying a Containing App to Older

C - dlopen dlsym

旧巷老猫 提交于 2019-11-28 03:57:53
----------------------------------------------------------------------------- dlsym ----------------------------------------------------------------------------- 测试dlsym打开的函数指针能不能多次调用 #include <stdio.h> #include <dlfcn.h> #include <unistd.h> #include <time.h> int main(){ int (*func)(int a, int b); void *handle = NULL; int c; char *myso = "./mylib.so"; if((handle = dlopen(myso, RTLD_NOW)) != NULL) { printf("success\n"); func = (void(*)())dlsym(handle, "add"); if(func != NULL){c=(*func)(1,2);} printf("1--%d",c); if(func != NULL){c=(*func)(2,2);} printf("\n2--%d",c); dlclose(handle); } else

dlopen - Undefined symbol error

折月煮酒 提交于 2019-11-28 00:38:27
问题 I'm using dlopen to load a shared library at run time dlopen("SharedLibarary1.so", RTLD_NOW | RTLD_GLOBAL); In that shared object I refer to a const char* defined in another shared library "SharedLibarary2.so". The Executable, and both the libraries are built using -rdynamic. But I still get the run time error when using dlopen: "/usr/lib/SharedLibarary1.so: undefined symbol" and points to the mangled const char* has the undefined symbol. Whith GDB "info share" I can see that the second

Is there an elegant way to avoid dlsym when using dlopen in C?

百般思念 提交于 2019-11-27 22:30:26
I need to dynamically open a shared library lib.so if a specific condition is met at runtime. The library contains ~700 functions and I need to load all their symbols. A simple solution is to define the function pointers to all symbols contained in lib.so , load the library using dlopen and finally get the addresses of all symbols using dlsym . However, given the number of functions, the code implementing this solution is very cumbersome. I was wondering if a more elegant and concise solution exists, maybe with an appropriate use of macros for defining the function pointers. Thanks! You could

Using dlopen() on an executable

折月煮酒 提交于 2019-11-27 17:46:33
问题 I need to call a function from another program. If the other program were a library, I could simply use dlopen and dlsym to get a handle to the function. Unfortunately, the other program is a Unix Executable, and building it as a library is not an option. Trying dlopen() on the executable gives this error message: dlopen([...]/testprogram, 1): no suitable image found. Did find: [...]/testprogram: can't map This isn't surprising, as dlopen is meant for use with libraries, not executables. Is

library path when dynamically loaded?

强颜欢笑 提交于 2019-11-27 11:51:08
How can I get the path of the shared library from within the library itself? In other words, let's say that library X is loaded using dlopen() , how can I get access to the path that was used to load the said library from within the library itself? Note that I cannot have the agent that loaded the library in the first place hand me this parameter. UPDATED: Here is way that works with static variables: std::string wdir; namespace { class dynamic_library_load_unload_handler { public: dynamic_library_load_unload_handler(){ Dl_info dl_info; dladdr((void *) NP_Initialize, &dl_info); std::string

MatLab error: cannot open with static TLS

大城市里の小女人 提交于 2019-11-27 10:23:21
Since a couple of days, I constantly receive the same error while using MATLAB which happens at some point with dlopen . I am pretty new to MATLAB, and that is why I don't know what to do. Google doesn't seem to be helping me either. When I try to make an eigenvector, I get this: Error using eig LAPACK loading error: dlopen: cannot load any more object with static TLS I also get this while making a multiplication: Error using * BLAS loading error: dlopen: cannot load any more object with static TLS I did of course look for the solutions to this problem, but I don't understand too much and don

Multiple instances of singleton across shared libraries on Linux

笑着哭i 提交于 2019-11-27 09:29:03
问题 My question, as the title mentioned, is obvious, and I describe the scenario in details. There is a class named singleton implemented by singleton pattern as following, in file singleton.h: /* * singleton.h * * Created on: 2011-12-24 * Author: bourneli */ #ifndef SINGLETON_H_ #define SINGLETON_H_ class singleton { private: singleton() {num = -1;} static singleton* pInstance; public: static singleton& instance() { if (NULL == pInstance) { pInstance = new singleton(); } return *pInstance; }