shared-libraries

what are the pros and cons of using a DLL?

谁都会走 提交于 2019-12-04 06:20:28
Windows still use DLLs and Mac programs seem to not use DLL at all. Are there benefits or disadvantages of using either technique? If a program installation includes all the DLL it requires so that it will work 100% well, will it be the same as statically linking all the libraries? MacOS X, like other flavours of Unix, use shared libraries, which are just another form of DLL. And yes both are advantageous as the DLL or shared library code can be shared between multiple processes. It does this by the OS loading the DLL or shared library and mapping it into the virtual address space of the

Hack the standard function in library and call the native library function afterwards

两盒软妹~` 提交于 2019-12-04 05:45:03
问题 I am trying to hack the malloc function to call my malloc function first.Once my malloc function is executed within that, I want to invoke the standard malloc. But, I am getting a recursion, since it is just loading my defined malloc. How can i fix the below code? #include <dlfcn.h> #include "stdio.h" //#include "stdlib.h" void *handle; void *handle_malloc; int (*loadprg)(void); void * (*malloc_sysm)(size_t); void init() { handle = dlopen ("/export/home/joshis1/Foxtel/temp/libloadmap.so",

What's the order for gcc to link unresolved symbol in static library

北战南征 提交于 2019-12-04 04:56:16
问题 When debug the function symbols conflicts problem, I find a strange behavior of gcc i couldn't understand, illustrate by the following sample code: main.c #include <stdio.h> int main() { b(); a(); } a.c #include <stdio.h> void a(void) { printf("func a in a\n"); } b.c #include <stdio.h> void a() { printf("func a in b\n"); } void b() { printf( "func b try to call a \n"); a(); } compile: gcc -c a.c gcc -c b.c ar -cr liba.a a.o ar -cr libb.a b.o gcc main.c liba.a libb.a execute: ./a.out func b

Global/Static variables initialization issue with __attribute__((constructor)) in shared library

耗尽温柔 提交于 2019-12-04 04:46:30
问题 I meet an issue with global/static variables' initialization with __attribute__((constructor)) in shared library, that certain variables seem to be initialized twice. Below are code snippets: shared.cpp struct MyStruct { MyStruct(int s = 1) : s(s) { printf("%s, this: %p, s=%d\n", __func__, this, s); } ~MyStruct() { printf("%s, this: %p, s=%d\n", __func__, this, s); } int s; }; MyStruct* s1 = nullptr; std::unique_ptr<MyStruct> s2 = nullptr; std::unique_ptr<MyStruct> s3; MyStruct s4; void

What is the meaning of this ImportError when importing a Cython generated .so file?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 04:23:16
I am walking through the Cython documentation and building each of the example apps. I'm a little stuck at Using C Libraries. After successfully building the .so file and attempting to import it in a python file called test.py the following error is thrown. $ python3.2 test.py Traceback (most recent call last): File "test.py", line 12, in <module> from queue import Queue ImportError: dlopen(/Users/jeremy/Development/labs/python/cython_lib_wrapper/queue.so, 2): Symbol not found: _queue_free Referenced from: /Users/jeremy/Development/labs/python/cython_lib_wrapper/queue.so Expected in: flat

Undefined reference to 'dlsym' and 'dlopen'

寵の児 提交于 2019-12-04 04:19:25
I am compiling using arm-linux-gnueabi-g++ version 4.7.3. I have the arm-linux-gnueabi libraries installed at location: /usr/arm-linux-gnueabi/lib, it contains libdl.a, libdl.so, libdl.so.2, and libdl-2.19.so. libdl.so links to libdl.so.2 which links to libdl-2.19.so. I am trying to link against the dl library (see command string below), but I always get the undefined reference errors. arm-linux-gnueabi-g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o -L../../work -L/usr/arm-linux-gnueabi/lib -lComms -lConsole -lUtilities -ldl ../../work/libUtilities.so:

Java: load shared libraries with dependencies

偶尔善良 提交于 2019-12-04 04:05:51
I am wrapping a shared library (written in C) with Java using JNA. The shared library is written internally, but that library uses functions from another external library, which again depends another external library. So the situation is something like this: ext1 <- ext2 <- internal I.e. the internal uses external library ext2 which again uses external library ext1. What I have tried is: System.loadLibrary("ext1"); System.loadLibrary("ext2"); NativeLIbrary.loadLibrary("internal",xxx.class); This approach fails with "UnresolvedException" when loading the library "ext2"; the linker complains

Shared Library Constructor is not executed

青春壹個敷衍的年華 提交于 2019-12-04 03:43:01
I have the following problem. I write a shared library #include <stdio.h> #include <stdlib.h> static void __attribute__ ((constructor)) test_init(void); static void __attribute__ ((destructor)) test_clean(void); /* Initialization */ static void test_init(void){ fprintf(stderr,"initialized\n"); fflush(stderr); } /* CleanUp */ static void test_clean(void){ fprintf(stderr,"cleaned up\n"); fflush(stderr); } double test (double x){ return 2.0*x; } And compile it using gcc -c -fPIC testlib.c -o testlib.o ld -shared -o libtest.so testlib.o Then I include it into a test program #include <stdio.h>

Calling a Fortran function from Julia, returning an array: unknown function, segfault?

余生颓废 提交于 2019-12-04 03:21:35
问题 I want to call functions in my Fortran library from Julia. In this case, I have a function eye that takes an Integer, and returns a two-dimensional array of integers. The Fortran module is compiled into a shared library using $ gfortran -shared -fPIC -o matrix_routines.so matrix_routines.f90 And thereafter I am attempting to call it from the interactive Julia interpreter like that (name obtained from nm ): julia> n=5 5 julia> ccall( (:__matrix_routines_MOD_eye, "/path/to/library/matrix

“No rule to make target” error in cmake when linking to shared library

倖福魔咒の 提交于 2019-12-04 03:17:28
问题 In Ubuntu, I have downloaded a third-party shared library, mylibrary.so , which I have placed in the directory /home/karnivaurus/Libraries . I have also placed the associated header file, myheader.h , in the directory /home/karnivaurus/Headers . I now want to link to this library in my C++ code, using cmake. Here is my CMakeLists.txt file: cmake_minimum_required(VERSION 2.0.0) project(DemoProject) include_directories(/home/karnivaurus/Headers) add_executable(demo demo.cpp) target_link