shared-libraries

Identifying which Linux system library contains a function

血红的双手。 提交于 2019-11-29 13:21:49
I am using a dev system where I have to specify the lib name when accessing a function inside it. I've used functions like open() before, and somehow found out that they're in libc.so. Now I want to use lstat(), but it appears that this one is not in libc. Sadly, the man pages I looked at do not document the location of the functions. So, two questions: Can someone tell which lib hosts lstat? How can I generally find this out? Other than using grep "name" on all files in the lib folder, I mean. Build a simple testcase in C, compile it and run 'ldd -r' on it to check what libs are loaded. If

Get functions names in a shared library programatically

喜欢而已 提交于 2019-11-29 13:19:27
Can I get list of all functions names from a shared library (Linux only) programmatically when I am using dl_open() ? I want something like this: std::vector<std::string> list_all_functions(void *dl) { //... what can I do here? } int main() { void * dl = dl_open("./mylib.so", RTLD_NOW); auto functions = list_all_functions(dl); //... dl_close(dl); return 0; } Example library (mylib.so) Header (.h): extern "C" { int sum (int a, int b); } Source (.c): int sum (int a, int b) { return a + b; } Dirty hack that I know: use nm or objdump utility There is no libc function to do that. However, you can

gcc - A static library with undefined symbols?

隐身守侯 提交于 2019-11-29 12:36:36
问题 I'm trying to build a project using a static library, so that the binary can be used even if the library isn't installed. However, I get lots of errors about undefined symbols when I try to do so. Looking at the library, I see it has tons of undefined symbols, even though it's a .a static lib: nm - u /usr/local/lib/libthis.a .... U EVP_DigestFinal_ex U EVP_DigestInit_ex U EVP_DigestUpdate U EVP_MD_CTX_cleanup U EVP_MD_CTX_init Those seem to be from openssl; others seem to be from libbzip2;

How can I share library between two program in c

↘锁芯ラ 提交于 2019-11-29 12:31:14
I want to use same library functions (i.e. OpenSSL library ) in two different programs in C for computation. How can I make sure that both program use a common library , means only one copy of library is loaded into shared main memory and both program access the library from that memory location for computation? For example, when 1st program access the library for computation it is loaded into cache from main memory and when the 2nd program wants to access it later , it will access the data from cache ( already loaded by 1st program), not from main memory again. I am using GCC under Linux. Any

Linking shared library in linux kernel

纵然是瞬间 提交于 2019-11-29 11:54:10
I would like to modify the linux kernel. I would like to use functions from a shared library (an .so file) in file kernel/panic.c . Unfortunately I don't know how to compile it. When I put it in to the Makefile I receive the following error: ld: attempted static link of dynamic object . Is there a way to put the shared library file to the Linux kernel or do I need to recompile my library to gain an object file. It is not possible to link shared library into kernel code ( ELF shared objects are a user-space thing, using ld-linux(8) ...) You should consider making a kernel module (and use

How to extract C source code from .so file?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 11:39:14
问题 I am working on previously developed software and source code is compiled as linux shared libraries (.so) and source code is not present. Is there any tool which can extract source code from the linux shared libraries? Thanks, Ravi 回答1: There isn't. Once you compile your code there is no trace of it left in the binary, only machine code. Some may mention decompilers but those don't extract the source, they analyze the executable and produce some source that should have the same effect as the

making gcc prefer static libs to shared objects when linking?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 11:36:26
问题 When linking against libraries using the -l option (say -lfoo ), gcc will prefer a shared object to a static library if both are found (will prefer libfoo.so to libfoo.a ). Is there a way to make gcc prefer the static library, if both are found? The issue I'm trying to solve is the following: I'm creating a plugin for an application (the flight simulator called X-Plane), with the following constraints: the plugin is to be in the form of a 32 bit shared object, even when running on a 64 bit

undefined symbol for self-built llvm opt?

非 Y 不嫁゛ 提交于 2019-11-29 11:33:40
I write a simple llvm plugin pass that requires opt to load xxx.so file and run a ModulePass. The strange thing is that when I use deb package opt (e.g., from apt-get , let's call it opt-3.7 ), the plugin works fine (the drawback is that it is a Release build); however when I use the opt I build myself (simplify call it opt ), it frequently complains: Error opening 'xxx.so': xxx.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE using c++filt I know that opt cannot find llvm::FunctionPass::createPrinterPass

how to force linker to use shared library instead of static library?

陌路散爱 提交于 2019-11-29 11:26:30
问题 This is a quote from Linux programming book: % gcc -o app app.o -L. –ltest Suppose that both libtest.a and libtest.so are available.Then the linker must choose one of the libraries and not the other.The linker searches each directory (first those specified with -L options, and then those in the standard directories).When the linker finds a directory that contains either libtest.a or libtest.so , the linker stops search directories. If only one of the two variants is present in the directory,

Python ImportError - undefined symbol - for custom C++ module

試著忘記壹切 提交于 2019-11-29 11:21:27
问题 I've been developing a Python module in C++ using OpenCV 2.3 through 2.4.2, on Ubuntu 11.04. OpenCV was built from source. I'm not using the version of OpenCV from the Ubuntu repositories. My Python module compiles with no issues and is loaded in Python properly. However, when I compile this module on Ubuntu 11.10 or 12.04, I get an ImportError with the message "undefined symbol" when trying to load it in Python. This is how I compile the module: g++ -fPIC -shared `pkg-config --cflags --libs