shared-libraries

How do I view the list of functions a Linux shared library is exporting?

点点圈 提交于 2019-11-27 02:35:12
I want to view the exported functions of a shared library on Linux. What command allows me to do this? (On Windows I use the program depends) What you need is nm and its -D option: $ nm -D /usr/lib/libopenal.so.1 . . . 00012ea0 T alcSetThreadContext 000140f0 T alcSuspendContext U atanf U calloc . . . Exported sumbols are indicated by a T . Required symbols that must be loaded from other shared objects have a U . Note that the symbol table does not include just functions, but exported variables as well. See the nm manual page for more information. user2391685 objdump -T *.so may also do the job

LD_PRELOAD equivalent for Windows to preload shared libraries

╄→尐↘猪︶ㄣ 提交于 2019-11-27 02:31:47
问题 I'm trying to do exactly what LD_PRELOAD does, i.e. preload a shared library or DLL files on Windows to a given program to override certain functions. Is there a LD_PRELOAD equivalent for Windows? I don't have any specific functionalities in mind. I just know that this is possible on Linux, and I'm curious about how overloading a native DLL can be done on Windows. 回答1: AppInit_DLLs. http://support.microsoft.com/kb/197571 But see also: AppInit_DLLs should be renamed Deadlock_Or_Crash_Randomly

Build .so file from .c file using gcc command line

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 02:22:49
I'm trying to create a hello world project for Linux dynamic libraries (.so files). So I have a file hello.c: #include <stdio.h> void hello() { printf("Hello world!\n"); } How do I create a .so file that exports hello() , using gcc from the command line? dreamcrash To generate a shared library you need first to compile your C code with the -fPIC (position independent code) flag. gcc -c -fPIC hello.c -o hello.o This will generate an object file (.o), now you take it and create the .so file: gcc hello.o -shared -o libhello.so EDIT : Suggestions from the comments: You can use gcc -shared -o

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

Dependency Walker equivalent for Linux? [duplicate]

*爱你&永不变心* 提交于 2019-11-27 01:47:12
问题 This question already has an answer here: Hierarchical ldd(1) 4 answers I need a tool to show all the shared library dependencies in some graphical way, not just with ldd on each .so . For MS Windows Dependency Walker works. Is there anything for Linux? . 回答1: Try binscan or ELF Library Viewer 来源: https://stackoverflow.com/questions/6977298/dependency-walker-equivalent-for-linux

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

Why does GCC create a shared object instead of an executable binary according to file?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 01:44:28
I have a library I am building. All of my objects compile and link successively when I run either one of: ar rcs lib/libryftts.a $^ gcc -shared $^ -o lib/libryftts.so in my Makefile. I also am able to successfully install them into /usr/local/lib When I test the file with nm, all the functions are there. My problem is that when I run gcc testing/test.c -lryftts -o test && file ./test or gcc testing/test.c lib/libryftts.a -o test && file ./test it says: test: ELF 64-bit LSB shared object instead of test: ELF 64-bit LSB executable as I would expect. What am I doing wrong? What am I doing wrong?

Loading multiple shared libraries with different versions

断了今生、忘了曾经 提交于 2019-11-27 00:47:17
问题 I have an executable on Linux that loads libfoo.so.1 (that's a SONAME ) as one of its dependencies (via another shared library). It also links to another system library, which, in turn, links to a system version, libfoo.so.2 . As a result, both libfoo.so.1 and libfoo.so.2 are loaded during execution, and code that was supposed to call functions from library with version 1 ends up calling (binary-incompatible) functions from a newer system library with version 2, because some symbols stay the

unused DT entry: type 0x1d arg

北城余情 提交于 2019-11-27 00:42:52
问题 I am using android NDK- r10d to build Android x86 executable (shared linking) that runs on adb shell. On run time, I am getting the following warning: WARNING: linker: ./myapp: **unused DT entry:** type 0x1d arg 0x4a604 I am using a rooted Nexus Player to test the executable. And my build machine is Ubuntu 14.04 (also tried on Fedora 14 machine). 回答1: What are "unused DT entry" errors? If you have reached this page, it's probably because you have compiled or attempted to run some binaries on

Elegantly call C++ from C

冷暖自知 提交于 2019-11-27 00:13:48
We develop some project in plain C (C99). But, we have one library as source codes (math library) in C++ . We need this library so I would like to ask, what is the most elegant way to integrate this source codes? Ratio between sizes of C and C++ is 20:1 so moving to C++ is not the option. Should we use static library? DLL? (It's all on Windows). EDIT: Based on discussion in the comment, I should point out that separating things into a C-compatible struct duck and a derived class Duck is probably unnecessary. You can probably safely shovel the implementation into struct duck and eliminate class