dynamic-linking

C/C++ How Does Dynamic Linking Work On Different Platforms?

橙三吉。 提交于 2019-11-28 21:04:46
问题 How does dynamic linking work generally? On Windows (LoadLibrary), you need a .dll to call at runtime, but at link time, you need to provide a corresponding .lib file or the program won't link... What does the .lib file contain? A description of the .dll methods? Isn't that what the headers contain? Relatedly, on *nix, you don't need a lib file... How how does the compiler know that the methods described in the header will be available at runtime? As a newbie, when you think about either one

How to link host code with a static CUDA library after separable compilation?

允我心安 提交于 2019-11-28 19:00:28
Alright, I have a really troubling CUDA 5.0 question about how to link things properly. I'd be really grateful for any assistance! Using the separable compilation features of CUDA 5.0, I generated a static library (*.a). This nicely links with other *.cu files when run through nvcc, I have done this many times. I'd now like to take a *.cpp file and link it against the host code in this static library using g++ or whatever, but not nvcc. If I attempt this, I get compiler errors like undefined reference to __cudaRegisterLinkedBinary I'm using both -lcuda and -lcudart and, to my knowledge, have

CMake and order dependent linking of shared libraries

纵然是瞬间 提交于 2019-11-28 18:38:18
I have a few small components that I am building as shared libraries for my main application. Lets use an example of liba and libb . Each is built within their own subdirectory as follows: add_library(liba SHARED a.cpp) Then, in the root project folder, I need to link my main application to both. include_directories(a) include_directories(b) add_executable(dummy dummy.cpp) target_link_libraries(dummy a b) CMake runs fine with this, and my application compiles but fails to link. The problem is that b references a. If I supply the order of the libraries while linking as target_link_libraries

How can I find which ELF dependency is not fulfilled?

旧巷老猫 提交于 2019-11-28 12:02:19
I've built a test ELF program using the LSB SDK ( note that my question is not specific to LSB ): $ /opt/lsb/bin/lsbcc tst.c $ ls -l a.out -rwxr-xr-x 1 math math 10791 2009-10-13 20:13 a.out $ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped But I am unable to launch it ( yes, I assure you the file is in the directory... ): $ ./a.out bash: ./a.out: No such file or directory $ uname -a Linux math 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:48:52 UTC 2009 x86_64 GNU/Linux I think there is an ELF

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

C program without header

*爱你&永不变心* 提交于 2019-11-28 05:10:55
问题 I write "hello world" program in C. void main() { printf("Hello World"); } // note that I haven't included any header file The program compiles with warning as vikram@vikram-Studio-XPS-1645:~$ gcc hello.c hello.c: In function ‘main’: hello.c:2:2: warning: incompatible implicit declaration of built-in function ‘printf’ vikram@vikram-Studio-XPS-1645:~$ ./a.out Hello Worldvikram@vikram-Studio-XPS-1645:~$ How is this possible? How does the OS link a library without including any header? 回答1: The

Linking shared library in linux kernel

瘦欲@ 提交于 2019-11-28 05:08:39
问题 This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated 4 years ago . 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

Loading multiple shared libraries with different versions

笑着哭i 提交于 2019-11-28 05:03:58
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 same. The result is usually stack smashing and a subsequent segfault. Now, the library which links

How to call a function from a shared library?

亡梦爱人 提交于 2019-11-28 04:46:10
What is the easiest and safest way to call a function from a shared library / dll? I am mostly interested in doing this on linux, but it would be better if there were a platform-independent way. Could someone provide example code to show how to make the following work, where the user has compiled his own version of foo into a shared library? // function prototype, implementation loaded at runtime: std::string foo(const std::string); int main(int argc, char** argv) { LoadLibrary(argv[1]); // loads library implementing foo std::cout << "Result: " << foo("test"); return 0; } BTW, I know how to

Create .SO files on Linux without using PIC (position independent code) (x86 32bit)

荒凉一梦 提交于 2019-11-28 02:02:30
问题 As far as I know, x86 assembly code is very much constrained by the limited amount of registers. When I learnt that on Linux, to create a .so file, one has to specify the -fPIC command line argument to gcc in order to create position independent code, I couldn't believe it first. As far as I know, the elf file format supports relocations, just like the - in my eyes much better - Windows DLL system works: On Windows the linker relocates all the offsets in the DLLs, if this is necessary. I