shared-libraries

why do we need the shared library during compile time

孤者浪人 提交于 2019-12-03 12:21:49
Why we need the presence of the shared library during the compile time of my executable? My reasoning is that since shared library is not included into my executable and is loaded during the runtime, it is not supposed to be needed during compile time. Or Am I missing something? #include<stdio.h> int addNumbers(int, int); //prototype should be enough, no? int main(int argc, char* argv[]){ int sum = addNumbers(1,2); printf("sum is %d\n", sum); return 0; } I had the libfoo.so in my current dir but I changed its name to libfar.so to find that shared lib is needed at compile or it doesn't compile.

Accessing .so libraries using dlopen() throws undefined symbol error

不想你离开。 提交于 2019-12-03 12:10:37
问题 I'm trying to dynamically load a camera library .so file into a Linux executable to gain access to simple camera functions. I'm attempting to do this by: if ( (newHandle = dlopen("./libCamera.so",RTLD_LAZY | RTLD_GLOBAL)) == NULL ) { printf( "Could not open file : %s\n", dlerror() ); return 1; } However this fails and I receive the following output: "Could not open file : libCamera.so: undefined symbol: ZTVN10 _cxxabiv117__class_type_infoE" How do I find out what symbols it is relying on? 回答1

Error handling strategies in a shared library - C

拟墨画扇 提交于 2019-12-03 12:06:17
I am writing a cross platform shared library ( .so in linux and .dll in windows) using C. Currently when there is a error, library functions returns the proper error code and writes error information into the stderr . Library functions also emits some information and debug messages to stdout . This works well for console based clients. Now this library will have client programs that uses GUI programmed using C++ & wxWidgets. I am wondering what would be the best practices in handling the errors and notifying it? Can a UI application access data coming to stdout and stderr on all platforms? An

Why does gcc force PIC for x64 shared libs?

泄露秘密 提交于 2019-12-03 12:04:32
Trying to compile non-PIC code into a shared library on x64 with gcc results in an error, something like: /usr/bin/ld: /tmp/ccQ2ttcT.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC This question is about why this is so. I know that x64 has RIP-relative addressing which was designed to make PIC code more efficient. However, this doesn't mean load-time relocation can't be (in theory) applied to such code. Some online sources, including this one (which is widely quoted on this issue) claim that there's some inherent limitation

Why LD_LIBRARY_PATH is BAD and the correct way to load dynamic libraries

五迷三道 提交于 2019-12-03 11:33:08
问题 So, I have a program that runs with OpenBlas and I want to compile it. The linking process looks like this: gcc -o prog prog.o -O3 -I/opt/OpenBLAS/include -L/opt/OpenBLAS/lib -lopenblas So far so good. If I remove the -L option, I get an error in the linking process /usr/bin/ld: cannot find -lopenblas With the -L everything links without errors. However, when I try to run it I get the following error: ./prog: error while loading shared libraries: libopenblas.so.0: cannot open shared object

nm symbol output t vs T in a shared so library

醉酒当歌 提交于 2019-12-03 11:19:23
问题 I have added a new function (fuse_lowlevel_notify_inval_directory) in user space fuse library. The compilation and creation of libfuse.so is finished without error. But when my application tries to use this new function, the linker is throwing error: undefined reference to `fuse_lowlevel_notify_inval_directory' collect2: ld returned 1 exit status When I checked with nm nm ../libfuse.so | grep inval 00000000000154ed T fuse_invalidate **000000000001e142 t fuse_lowlevel_notify_inval_directory**

Linking with versioned shared library in Android NDK

我与影子孤独终老i 提交于 2019-12-03 10:58:37
问题 I am trying to load two shared libraries in my Android application through the loadLibrary call: System.loadLibrary("mywrapper"); System.loadLibrary("crypto"); I keep running catching the `UnsatisfiedLinkError. Here is a more detailed version of the error. Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1969]: 130 could not load needed library 'libcrypto.so.1.0.0' for 'libmywrapper.so' (load_library[1111]: Library 'libcrypto.so.1.0.0' not found) Any ideas? After

Can a C++ Static Library link to shared library?

巧了我就是萌 提交于 2019-12-03 10:30:33
Say I have a static C++ lib, static.lib and I want to call some functions from a C++ shared lib, say shared.lib. Is it possible? Now assume that I have another shared lib, say shared2.lib which links to static.lib but does not link to shared.lib. Does the linker automatically link shared2.lib to shared.lib in this case? I am using Microsoft Visual Studio 2003. Static libraries are not linked. They are just a collection of object files (*.obj or *.o) that are archived together into a library file (kind of like a tar/zip file) to make it easier for the linker to find the symbols it needs. A

Include framework in Xcode static library?

故事扮演 提交于 2019-12-03 10:02:03
In short: Is there a way to create a static library in Xcode such that when clients link with that library, they also link with the frameworks upon which that library depends? The problem: We have a shared Xcode project which contains multiple static library targets containing all of our common code. E.g., If a project wants to use the shared networking code, all they should have to do is link in our Network library. The problem is that the libraries don't seem to "include" the frameworks on which they depend. E.g., our Sound library uses the AudioToolkit.framework. Even when the Sound library

What does “Ex” stand for in Windows API function names?

心已入冬 提交于 2019-12-03 09:19:26
In windows APIs and various other libraries where I have seen multiple entry points to methods I have noticed the use of the Ex abbreviation in scenarios such as MyApiCall and MyApiCallEx. My assumption is that this stands for Extension or Extra could someone please confirm? Any history on why Ex was chosen rather then MyApiCall2 or similar would also be appreciated. I was under the impression it stood for extended, as in a more detailed interface for that particular library. For example, CreateFile with 4 parameters is the typical version and CreateFileEx with 17 is the version offering more