dlopen

Error: dlopen() Library not loaded Reason: image not found

爱⌒轻易说出口 提交于 2019-11-27 08:29:48
I am a newbie in this field. My laptop is Macbook air, Software: OS X 10.8.5 (12F45). I am running a code which gives me the following error: dlopen(/Users/ramesh/offline/build_icerec/lib/icecube/phys_services.so, 2): Library not loaded: /Users/ramesh/offline/build_icerec/lib/libphys-services.dylib Referenced from: /Users/ramesh/offline/build_icerec/lib/icecube/phys_services.so Reason: image not found I did google search and found variety of answers. I think the one that works is to use " -install_name @rpath/lib ". My question is, how to use -install_name @rpath/lib in my case? mah Shared

Creating a static C struct containing strings

五迷三道 提交于 2019-11-27 07:42:44
问题 I'm trying to create a dynamic library in Rust that exports a struct as a symbol that will be loaded into a C program via dlopen(). However, I'm was running into some segfaults when accessing the second string in the struct, so I made a small test program to try figure out what I'm doing wrong. This is the Rust code (test.rs), compiled with "rustc --crate-type dylib test.rs": #[repr(C)] pub struct PluginDesc { name: &'static str, version: &'static str, description: &'static str } #[no_mangle]

dynamic_cast fails when used with dlopen/dlsym

房东的猫 提交于 2019-11-27 02:42:53
问题 Intro Let me apologise upfront for the long question. It is as short as I could make it, which is, unfortunately, not very short. Setup I have defined two interfaces, A and B: class A // An interface { public: virtual ~A() {} virtual void whatever_A()=0; }; class B // Another interface { public: virtual ~B() {} virtual void whatever_B()=0; }; Then, I have a shared library "testc" constructing objects of class C, implementing both A and B, and then passing out pointers to their A-interface:

linux dlopen: can a library be “notified” when it is loaded?

不问归期 提交于 2019-11-27 02:13:57
问题 Is there a way for a shared library to be "notified" when it is loaded? In other words, let's say I use dlopen on a shared library, is there a function that is automatically called (if present) on the shared library (e.g. main?) 回答1: Libraries should export initialization and cleanup routines using the gcc __attribute__((constructor)) and __attribute__((destructor)) function attributes. See the gcc info pages for information on these. Constructor routines are executed before dlopen returns

Main Program and Shared Library initializes same static variable in __static_initialization_and_destruction_0

筅森魡賤 提交于 2019-11-27 01:46:38
问题 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? 回答1: This is a case where the runtime linker only wants a

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

廉价感情. 提交于 2019-11-26 22:59: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

how to call function in executable from my library?

試著忘記壹切 提交于 2019-11-26 22:58:16
I have an executable and a dynamic library (.so). The library exports some symbols and executable calls it successfully. But I want to make possible to library call executable's functions. I've tried to do following in executable: //test extern "C" void print(const char * str) { std::cout << str << std::endl; } and this in library: extern "C" void print(const char *); but when i call dlopen in executable (to load the library) it returns error undefined symbol: print . how can i fix it? ninjalj In Linux/ELF you can pass the -export-dynamic option to the linker ( -rdynamic on the compiler driver

building a .so that is also an executable

会有一股神秘感。 提交于 2019-11-26 17:19:41
So everyone probably knows that glibc's /lib/libc.so.6 can be executed in the shell like a normal executable in which cases it prints its version information and exits. This is done via defining an entry point in the .so. For some cases it could be interesting to use this for other projects too. Unfortunately, the low-level entry point you can set by ld's -e option is a bit too low-level: the dynamic loader is not available so you cannot call any proper library functions. glibc for this reason implements the write() system call via a naked system call in this entry point. My question now is,

how to call function in executable from my library?

大憨熊 提交于 2019-11-26 08:32:40
问题 I have an executable and a dynamic library (.so). The library exports some symbols and executable calls it successfully. But I want to make possible to library call executable\'s functions. I\'ve tried to do following in executable: //test extern \"C\" void print(const char * str) { std::cout << str << std::endl; } and this in library: extern \"C\" void print(const char *); but when i call dlopen in executable (to load the library) it returns error undefined symbol: print . how can i fix it?

dlopen from memory?

南楼画角 提交于 2019-11-26 07:34:58
问题 I\'m looking for a way to load generated object code directly from memory. I understand that if I write it to a file, I can call dlopen to dynamically load its symbols and link them. However, this seems a bit of a roundabout way, considering that it starts off in memory, is written to disk, and then is reloaded in memory by dlopen. I\'m wondering if there is some way to dynamically link object code that exists in memory. From what I can tell there might be a few different ways to do this: