dynamic-linking

g++ why don't you have to link iostream binaries but for pthread you do?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 01:24:11
问题 If you have a very basic C++ program that only uses the 'cout' object, you can include iostream in the source file and then when you compile it you don't have to link any external libraries. In other words, you can simply run g++ main.cpp -c g++ main.o -o program ./program When you want to use more complicated objects such as threads, not only do you include pthread, but when you link the program you have to link to a library. g++ main.cpp -c g++ main.o -lpthread -o program ./program So my

Building a python module and linking it against a MacOSX framework

你离开我真会死。 提交于 2019-12-09 14:58:07
问题 I'm trying to build a Python extension on MacOSX 10.6 and to link it against several frameworks (i386 only). I made a setup.py file, using distutils and the Extension object. I order to link against my frameworks, my LDFLAGS env var should look like : LDFLAGS = -lc -arch i386 -framework fwk1 -framework fwk2 As I did not find any 'framework' keyword in the Extension module documentation, I used the extra_link_args keyword instead. Extension('test', define_macros = [('MAJOR_VERSION', '1'), ,(

Size difference between static and dynamic (debug) library and impact on final exe

孤人 提交于 2019-12-09 12:36:17
问题 I never put much thought into the size difference between a static library and a dynamic library until I downloaded pre-built libraries of boost today. I found that the static libraries of boost are much much bigger than the dynamic libraries. For example, the debug multi-threaded boost wave static library is 97.7 mb in size while the same library, but dynamic, is only 1.4 mb in size (including import library and dll)! That is a huge difference. Why is that? Second question, if I statically

Destructor of a global static variable in a shared library is not called on dlclose

你。 提交于 2019-12-09 11:59:41
问题 In a main program, I dlopen and dlclose ( LoadLibrary and FreeLibrary respectively) a shared library. The shared library contains a static variable that is instantiated upon dlopen , and destroyed upon dlclose . This behavior is consistent on MSVC 2008 and 2013, GCC 3.4.6, and Sunstudio 12.1. With GCC 4.9.1 and GCC 5.2.1 however, the destructor was no longer called on dlclose . Instead, it was called before program exit. The particularity of the static variable's class, is that in the

Patching code/symbols into a dynamic-linked ELF binary

大兔子大兔子 提交于 2019-12-09 10:37:37
问题 Suppose I have an ELF binary that's dynamic linked, and I want to override/redirect certain library calls. I know I can do this with LD_PRELOAD , but I want a solution that's permanent in the binary, independent of the environment, and that works for setuid/setgid binaries, none of which LD_PRELOAD can achieve. What I'd like to do is add code from additional object files (possibly in new sections, if necessary) and add the symbols from these object files to the binary's symbol table so that

Differences between static libraries and dynamic libraries ignoring how they are used by the linker/loader

喜夏-厌秋 提交于 2019-12-09 07:41:12
问题 I understand how static/dynamic libraries are used by the linker/loader. However why not have a single type of library file accompanied by compiler flags which indicate how the library should be linked (static vs dynamic)? By the simple fact that we do have static and dynamic libraries I presume these files have specific contents which enable static and dynamic linking respectively. Can someone throw some light on the differences between the contents of static and shared library files? 回答1:

Call C functions from 64-bit assembly

北慕城南 提交于 2019-12-08 10:38:03
问题 On ubuntu 16.04 $ cat hola.asm extern puts global main section .text main: mov rdi,message call puts ret message: db "Hola",0 $ nasm -f elf64 hola.asm $ gcc hola.o /usr/bin/ld: hola.o: relocation R_X86_64_PC32 against symbol `puts@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status Use: $gcc -fPIC hola.o -o hola && ./hola Hola The docs: -fPIC If supported for the target machine,

Linking a dynamic library to a static library that links to other static libraries

限于喜欢 提交于 2019-12-08 07:41:11
问题 In my C++ application I have a static library (libCOMMON.a) that links to boost libraries: system, filsystem, timer and chrono. I am using CMake and here is how I create and link libCOMMON.a: ADD_LIBRARY(COMMON ${COMMON_SRCS}) target_link_libraries(COMMON ${BOOST_LIB_DIR}/libboost_filesystem.a ${BOOST_LIB_DIR}/libboost_system.a ${BOOST_LIB_DIR}/libboost_timer.a ${BOOST_LIB_DIR}/libboost_chrono.a ) I also have plugins for this application that links to libCOMMON.a. The plugins are built as

forcing linking with a different SONAME than this of library

烂漫一生 提交于 2019-12-08 07:37:57
问题 How to link a binary in a manner to be compatible with two existing version of a library that have conflicting SONAME ? Those two versions don't share same SONAME prefix. One is libcapi10.so.3 and the other is libcapi10.so.4. I can't recompile them since i get them as binary, and since those are certified crypto libraries i can't request new one with right SONAME. Of course i would not have faced any problem if one was libcap10.so.3 and the other libcap10.so.3.1 since i would just need to

Measure time taken dynamically linking at program startup?

可紊 提交于 2019-12-08 04:02:39
问题 How can I measure the time spent dynamically linking at program startup? Solutions that come to mind and why I'm hesitant: 1) Print something the time right before running the program and at the start of main. This doesn't take into account possible code that runs before main -- initialization of globals and any resulting function calls. It's not automated out of the box and well, it strikes me as crude and of dubious accurately. 2) time command on an empty program that has all the same