dlopen

dlopen a dynamic library from a static library linux C++

女生的网名这么多〃 提交于 2019-12-06 21:07:44
I've a linux application that links against a static library (.a) and that library uses the dlopen function to load dynamic libraries (.so) If I compile the static library as dynamic and link it to the application, the dlopen it will work as expected, but if I use it as described above it won't. Can't a static library uses the dlopen function to load shared libraries? Thanks. There should be no problem with what you're trying to do: app.c: #include "staticlib.h" #include "stdio.h" int main() { printf("and the magic number is: %d\n",doSomethingDynamicish()); return 0; } staticlib.h: #ifndef _

What can cause dlopen: no suitable image found (can't map)?

走远了吗. 提交于 2019-12-06 19:56:26
问题 What can cause the following error when loading an additional bundle using dlopen: dlopen($(OBJ_DIR)/Test-20091217211256.ob, 6): no suitable image found. Did find: $(OBJ_DIR)/Test-20091217211256.ob: can't map Before this error, the process allocates large amounts of memory. (Substituted $(OBJ_DIR) in the error for the actual path to make it more legible). 回答1: One possibility is that the shared library you're trying to open isn't actually a shared library. Run the file(1) program on your

Memory leak reported by valgrind in dlopen?

爷,独闯天下 提交于 2019-12-06 18:19:57
问题 I've been debugging some app lately with valgrind, and I'm getting very weird reports from dlopen . ==1987== 32 bytes in 1 blocks are still reachable in loss record 1 of 2 ==1987== at 0x4C24477: calloc (vg_replace_malloc.c:418) ==1987== by 0x570F31F: _dlerror_run (dlerror.c:142) ==1987== by 0x570EEE0: dlopen@@GLIBC_2.2.5 (dlopen.c:88) <my call to dlopen> ==1987== ==1987== 264 bytes in 1 blocks are still reachable in loss record 2 of 2 ==1987== at 0x4C25153: malloc (vg_replace_malloc.c:195) =

c++ dynamic library dlopen error

爷,独闯天下 提交于 2019-12-06 13:21:59
I have two files: RollDice.cpp #include "RollDice.h" #include "./IPlugins.cpp" #include "./IPluginFunctions.cpp" #include <iostream> RollDice::RollDice(IPluginFunctions &iPluginFunctions) : IPlugins(iPluginFunctions) { //srand(time(NULL)); } RollDice::~RollDice() { } void RollDice::callPlugin(std::string paramsText, std::string dataText) { std::cout << "RollDice ;)\n"; } RollDice.h: #ifndef ROLLDICE_H_ #define ROLLDICE_H_ #include "./IPlugins.h" #include "./IPluginFunctions.h" class RollDice: public IPlugins { public: RollDice(IPluginFunctions &iPluginFunctions); virtual ~RollDice(); virtual

How to pass arguments to a method loaded from a static library in CPP

Deadly 提交于 2019-12-06 11:48:53
问题 I'm trying to write a program to use a static library of a C++ code into another C++ code. The first C++ code is hello.cpp : #include <iostream> #include <string.h> using namespace std; extern "C" void say_hello(const char* name) { cout << "Hello " << name << "!\n"; } int main(){ return 0; } The I made a static library from this code, hello.a , using this command: g++ -o hello.a -static -fPIC hello.cpp -ldl Here's the second C++ code to use the library, say_hello.cpp : #include <iostream>

How to export specific symbol from executables in GNU/Linux

ε祈祈猫儿з 提交于 2019-12-06 08:45:54
While loading dynamic libraries by ::dlopen() , exporting symbols from executables can be done by -rdynamic option, but it exports all the symbols of the executable, which results in bigger binary size. Is there a way to export just specific function(s)? For example, I have testlib.cpp and main.cpp as below: testlib.cpp extern void func_export(int i); extern "C" void func_test(void) { func_export(4); } main.cpp #include <cstdio> #include <dlfcn.h> void func_export(int i) { ::fprintf(stderr, "%s: %d\n", __func__, i); } void func_not_export(int i) { ::fprintf(stderr, "%s: %d\n", __func__, i); }

Automatically Creating Wrappers for Classes Loaded with dlopen()

可紊 提交于 2019-12-06 08:41:15
I'm writing a proxy class that loads a shared library with dlopen() and forwards its member functions to the appropriate members of the proxied class instance inside the loaded shared object behind the scenes. For example, the shared object has a Person class: class Person { ... void setName(std::string name); }; I've added a wrapper file that includes the person.h header and defines the following symbol: extern "C" { void Person_setName(void* instancePointer, std::string name); } This call just forwards to the person object which is the first argument, extern "C" to avoid the whole name

How to find the coverage of a library opened using dlopen()?

江枫思渺然 提交于 2019-12-06 08:08:47
I have a C++ library (.so) which is opened using dlopen() by another application. But I need to find the code coverage of this library while run within the application using gcov. Is it possible? If yes, how can it be done? If not, how can the issue be resolved? Firstly have your compiled your C++ library with the --coverage flag? I've never actually used a '.so' library with gcov before, so I'm not sure it would work anyway. Secondly could you arrange a test version of your application to not use dlopen() , but instead be linked to a static library(.a) version of your library and still make

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “cmsg_nxthdr” referenced by “libpcap.so”

試著忘記壹切 提交于 2019-12-06 07:15:39
问题 I am new to NDK. I am trying to create an app that can capture packets. I have compiled libpcap from https://github.com/the-tcpdump-group/libpcap Now when I try to run the application on an android tablet, it gives the following error 07-24 02:29:50.627: E/AndroidRuntime(2014): FATAL EXCEPTION: main 07-24 02:29:50.627: E/AndroidRuntime(2014): Process: com.example.lpcap, PID: 2014 07-24 02:29:50.627: E/AndroidRuntime(2014): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol

Calling function by name using dlsym in iOS

六月ゝ 毕业季﹏ 提交于 2019-12-06 06:51:39
问题 Can't I call a function by name in iOS? I have a C function called getstring . I am calling it as follows: void* handle = dlopen(NULL, RTLD_NOW); if (handle) { fp func = dlsym(handle, "getstring"); if (!func) responseField.text = [NSString stringWithUTF8String:dlerror()]; else { char* tmpStr = func(); responseField.text = [NSString stringWithUTF8String:tmpStr]; } } else { responseField.text = [NSString stringWithUTF8String:dlerror()]; } When this executes, responseFiled.text is set to dlsym(.