dlopen

Casting when using dlsym()

烈酒焚心 提交于 2019-12-05 07:16:48
I'm using dlsym() in C and I have a question whether the return value of dlsym() should be explicitly cast or if it is implicitly cast correctly. Here is the function: double (*(compile)(void))(double x, double y) { if (system("scan-build clang -fPIC -shared -g -Wall -Werror -pedantic " "-std=c11 -O0 -lm foo.c -o foo.so") != 0) { exit(EXIT_FAILURE); } void *handle; handle = dlopen("./foo.so", RTLD_LAZY); if (!handle) { printf("Failed to load foo.so: %s\n", dlerror()); exit(EXIT_FAILURE); } foo f; f = (foo)dlsym(handle, "foo"); if (!f) { printf("Failed to find symbol foo in foo.so: %s\n",

When exactly is gcc __attribute__((constructor)) run?

て烟熏妆下的殇ゞ 提交于 2019-12-05 04:15:15
Let's say I have an libA.so with GCC constructor. My program "program" depends on libA.so, so when I run it, libA.so gets opened and its constructor is executed. Now, I also have a module, libC.so, which also depends on libA. I run dlopen("libC.so") , which loads libC, and according to my experiments, also executes libA's constructor . Dependencies look like this: libA has the constructor libB also has a constructor libC depends on libA and libB program depends on libA program links libC via dlopen() Now, when I run the program: libA's constructor gets run before main() starts libB's

Memory leak reported by valgrind in dlopen?

半腔热情 提交于 2019-12-05 01:13:22
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) ==1987== by 0x400CD44: _dl_map_object_deps (dl-deps.c:506) ==1987== by 0x4012DA2: dl_open_worker (dl-open

Lua: C++ modules can't reference eachother, undefined symbol

…衆ロ難τιáo~ 提交于 2019-12-04 23:22:01
问题 I've created two modules (shared objects) CPU and SaveState as part of an emulator. Both are independently compiled into .so separate files, and loaded at runtime by a Lua script using require(); i.e.: SaveState = require("SaveState") CPU = require("CPU") Within CPU, there's a method that operates on a SaveState: int CPU::save_state(SaveState *state) { state->begin_section(savestate_namespace, savestate_data_size); state->write16(this->reg.af); state->write16(this->reg.bc); state->write16

What is causing sprof to complain about “inconsistency detected by ld.so”?

给你一囗甜甜゛ 提交于 2019-12-04 23:02:24
I'm trying to use sprof to profile some software (ossim) where almost all the code is in a shared library. I've generated a profiling file, but when I run sprof, I get the following error: > sprof /home/eca7215/usr/lib/libossim.so.1 libossim.so.1.profile -p > log Inconsistency detected by ld.so: dl-open.c: 612: _dl_open: Assertion `_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT' failed! The instructions I was following said that I needed libc version at least 2.5-34, I have libc version 2.12.2 (Gentoo, kernel 2.6.36-r5). I can't find any explanation as to what the error means or

dlopen() search path

余生颓废 提交于 2019-12-04 22:10:30
问题 is there a way to find out programmatically which paths are searched by dlopen() for shared objects? I always thought dlopen() would only look in /lib and /usr/lib but now I've seen that on Linux Mint several core components like libglib-2.0.so are in a wholly different folders, namely in /rofs/lib/i386-gnu-linux and some others. Is there a way to get to know all these paths that dlopen() will search through for a shared object? I already checked the environment variable LD_LIBRARY_PATH but

Several shared object using same proto leading the the error: file already exists in database

南笙酒味 提交于 2019-12-04 15:58:42
An error related to protobuf3 I have a project that have an c++ executable core, and several shared objects (.so, .dll) called plugins. When the core launches, it will load those plugins with dlopen. The core and plugins using protobuf as communication protocol, so they have to compile the generated .pb.cc and .ph.h files into their binaries to have the copy of the serializer/deserializer. And libprotobuf.so link to both the core and plugins. When I launch the core, it crushes with error: file already exists in database, same error in #863 I'm using protobuf-3 beta2, and Ubuntu 14.04. This

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

淺唱寂寞╮ 提交于 2019-12-04 15:40:49
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> #include <string> #include <dlfcn.h> using namespace std; int main(){ void* handle = dlopen("./hello.a",

Calling function by name using dlsym in iOS

守給你的承諾、 提交于 2019-12-04 13:38:55
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(...): symbol not found . This means dlopen works but not dlsym . I dumped the symbols in the binary

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

爷,独闯天下 提交于 2019-12-04 12:01:35
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 "cmsg_nxthdr" referenced by "libpcap.so"... 07-24 02:29:50.627: E/AndroidRuntime(2014): at java.lang