dynamic-library

dlopen() error image not found

徘徊边缘 提交于 2019-12-01 17:20:44
I have software that first loads a .dylib lets call libFirst.dylib using the following command: void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL); Later on inside a function from the loaded libFirst.dylib I attempt to load another .dylib using the same command but for libSecond.dylib, the loading of this shared library gives me the following warnings in my Xcode console: error warning: Ignored unknown object module at 0x129310 with type 0x8a8399 dlerror: dlopen(/path/libSecond.dylib, 9): Library not loaded: libFirst.dylib Referenced from: /path/libSecond.dylib Reason: image not

dlopen on new binary with same name returns old handle

假如想象 提交于 2019-12-01 13:48:21
I'm using dlopen to load dynamically generated code. The program calls the compiler on the code and generates a .so file which is then loaded by the program to extend itself. The problem is that if I use the same name for the generated code, the dlopen returns a handle to the old object, not the new one. The code looks like: …generate code into test.cpp system("gcc <args> test.cpp -o test.so"); void *handle = dlopen("test.so"); void *sym = dlsym(handle, "run"); (*sym)(); dlclose(handle); …Do other work …generate different code to test.cpp system("gcc <args> test.cpp -o test.so"); void *handle

Global variables, shared libraries and -fPIC effect

扶醉桌前 提交于 2019-11-30 08:05:43
问题 I made a piece of code which consists in a dynamic library ( lib.c ), and a main executable ( main.c ). In both files I define a global variable named: int global . Not very smart but it's not the question. When I compile the dynamic library the -fPIC option seems mandatory: gcc lib.c -fPIC -shared -o lib.so otherwise I get: /usr/bin/ld: /tmp/ccpUvIPj.o: relocation R_X86_64_32 against '.rodata' can not be used when making a shared object; recompile with -fPIC When I compile the executable it

Is there a downside to using -Bsymbolic-functions?

帅比萌擦擦* 提交于 2019-11-30 01:42:53
I recently discovered the linker option "-Bsymbolic-functions" in GNU ld: -Bsymbolic When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a program linked against a shared library to override the definition within the shared library. This option is only meaningful on ELF platforms which support shared libraries. -Bsymbolic-functions When creating a shared library, bind references to global function symbols to the definition within the shared library, if any. This option is only meaningful on ELF

Global variables, shared libraries and -fPIC effect

六眼飞鱼酱① 提交于 2019-11-29 05:58:45
I made a piece of code which consists in a dynamic library ( lib.c ), and a main executable ( main.c ). In both files I define a global variable named: int global . Not very smart but it's not the question. When I compile the dynamic library the -fPIC option seems mandatory: gcc lib.c -fPIC -shared -o lib.so otherwise I get: /usr/bin/ld: /tmp/ccpUvIPj.o: relocation R_X86_64_32 against '.rodata' can not be used when making a shared object; recompile with -fPIC When I compile the executable it is not. gcc main.c -fPIC -ldl gcc main.c -ldl Both work, but have different behaviours I can not

C++ Statically linked shared library

萝らか妹 提交于 2019-11-28 17:53:13
I have a shared library used by a another application beyond my control which requires *.so objects. My library makes use of sqlite3 which needs to be statically linked with it (I absolutely need a self-contained binary). When I try to compile and link my library: -fpic -flto -pthread -m64 -flto -static -shared I end up with the following error: /usr/bin/ld: /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/crtbeginT.o:

C++ linux: dlopen can't find .so library

試著忘記壹切 提交于 2019-11-28 09:26:36
Reworded Question (although it's been solved already): I've been having trouble using dlopen(3) to load a shared object library on linux. The library is part of a system of libraries built by me that are all loaded at runtime by a central executable. All of this is organized into a single workspace in Code::Blocks, where each project is given its own folder within a directory called Source, which is to be shipped with the program. The build directory of the executable is two directories backward from its own source code so that the exectuable and the Source folder are in the same directory,

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

CMake: how to produce binaries “as static as possible”

℡╲_俬逩灬. 提交于 2019-11-28 03:39:33
I would like to have control over the type of the libraries that get found/linked with my binaries in CMake. The final goal is, to generate binaries "as static as possible" that is to link statically against every library that does have a static version available. This is important as would enable portability of binaries across different systems during testing. ATM this seems to be quite difficult to achieve as the FindXXX.cmake packages, or more precisely the find_library command always picks up the dynamic libraries whenever both static and dynamic are available. Tips on how to implement

Linking Rust application with a dynamic library not in the runtime linker search path

大憨熊 提交于 2019-11-27 20:54:58
I have a shared library that I'd like to dynamically link into several separate binary Cargo applications. I include its location in the linker using the -- -L /path/to/dir format and the application compiles correctly with the significant decrease in binary size I expect. However, when checking the generated binary using ldd , I get a message saying that the library couldn't be found: casey@Gilthar-II:~/bot4/backtester/target/release$ ldd backtester linux-vdso.so.1 => (0x00007ffc642f7000) libalgobot_util.so => not found If I add the library to the /lib/x86_64-linux-gnu directory, the