dynamic-linking

Why doesn't the linker complain of duplicate symbols?

前提是你 提交于 2020-01-20 08:26:25
问题 I have a dummy.hpp #ifndef DUMMY #define DUMMY void dummy(); #endif and a dummy.cpp #include <iostream> void dummy() { std::cerr << "dummy" << std::endl; } and a main.cpp which use dummy() #include "dummy.hpp" int main(){ dummy(); return 0; } Then I compiled dummy.cpp to three libraries, libdummy1.a , libdummy2.a , libdummy.so : g++ -c -fPIC dummy.cpp ar rvs libdummy1.a dummy.o ar rvs libdummy2.a dummy.o g++ -shared -fPIC -o libdummy.so dummy.cpp When I try compile main and link the dummy

Why doesn't the linker complain of duplicate symbols?

徘徊边缘 提交于 2020-01-20 08:25:55
问题 I have a dummy.hpp #ifndef DUMMY #define DUMMY void dummy(); #endif and a dummy.cpp #include <iostream> void dummy() { std::cerr << "dummy" << std::endl; } and a main.cpp which use dummy() #include "dummy.hpp" int main(){ dummy(); return 0; } Then I compiled dummy.cpp to three libraries, libdummy1.a , libdummy2.a , libdummy.so : g++ -c -fPIC dummy.cpp ar rvs libdummy1.a dummy.o ar rvs libdummy2.a dummy.o g++ -shared -fPIC -o libdummy.so dummy.cpp When I try compile main and link the dummy

Mixing static libraries and shared libraries

南楼画角 提交于 2020-01-20 05:02:25
问题 I have a project where I have one static library libhelper.a and another with my actual shared object library, libtestlib.so . My goal is to link libhelper.a into libtestlib.so . Is that possible on Linux/BSD? When I tried and created a test program I got the following errors: ./prog1:/usr/local/lib/libtestlib.so.1.0: undefined symbol '' My guess is that this is occurring because libhelper.a was not compiled with -fPIC while libtestlib.so was. What is the proper way to build programs that use

relocation entry in linking (C programming)

房东的猫 提交于 2020-01-15 12:22:29
问题 still struggling to understand the relocation entry in Relocatable Object Files, let's say I have this simple C program: //main1.c void functionTest(); functionTest(){ ... } int main() { functionTest(); return 0; } my questions are: Q1. since everything is known to main1, so there is no relocation entry in .rel.text or .rel.data section of main1.o, is my understanding correct? Q2. below is a picture illustrates how DLL works, for libc.so, everything is known(it has all definitions just like

Can a dynamically linked library override a static one?

♀尐吖头ヾ 提交于 2020-01-15 10:14:55
问题 nokogori gem comes with its own version of libxml2 . Moreover it warns about libxml2.so of a different version being loaded before it was required: if compiled_parser_version != loaded_parser_version ["Nokogiri was built against LibXML version #{compiled_parser_version}, but has dynamically loaded #{loaded_parser_version}"] It basically compares LIBXML_DOTTED_VERSION macro and xmlParserVersion global variable: rb_const_set( mNokogiri, rb_intern("LIBXML_VERSION"), NOKOGIRI_STR_NEW2(LIBXML

Boost linking error: 'B5cxx11' symbols missing

元气小坏坏 提交于 2020-01-14 13:57:48
问题 Here's the issue: the code I'm using uses a big library which links against boost. When I compile with static linking, everything works fine. However, when I try dynamic linking I get a bunch of undefined reference errors. The first thought was obviously "I am not linking the boost program_options" library, but I looked, and it is there in the linking command (and it comes after the library that needs it). Among the different errors, though, this stood out: undefined reference to `

Linking QtCreator && OpenCv

ⅰ亾dé卋堺 提交于 2020-01-14 03:54:06
问题 I'm having a problem linking a library from opencv(2.3.1) and can't find a way to resolve it.. I'm using qtCreator with mingw and the pre-built vc10 dynamic lib files. So, here is what I have done till now: .pro file: TEMPLATE = app INCLUDEPATH += "E:/opencv/build/include/" INCLUDEPATH += "E:/opencv/build/include/opencv/" INCLUDEPATH += "E:/opencv/build/include/opencv2/" INCLUDEPATH += $$PWD/../opencv/build/x86/vc10 DEPENDPATH += $$PWD/../opencv/build/x86/vc10 win32:CONFIG(release, debug

statically linked shared object? Or a corrupt file?

爱⌒轻易说出口 提交于 2020-01-13 09:54:14
问题 I have a library that I got from a proprietary source and I'm trying to link against it but I'm getting the following error libxxx.so: file not recognized: File format not recognized collect2: ld returned 1 exit status and indeed $ ldd ./libxxx.so statically linked what does that exactly mean? Never saw a statically linked .so in my life. It might be worth noting that the last version of the same software included the same .so for which ldd shows the "normal" output and that works fine. $

interposers on Windows

泄露秘密 提交于 2020-01-11 10:35:23
问题 Is it possible to substitute system functions, as is possible on Linux and Solaris using the LD_PRELOAD For example by setting the environment variable: LD_PRELOAD=/path/to/mymalloc.so I would have my replacement malloc functions instead of in the C runtime already installed in the system libraries. All other functions in the system dll's would run as normal. 回答1: Microsoft Research has a library called Detours which allows you to intercept Win32 API calls. Detours is a library for

use RPATH but not RUNPATH?

那年仲夏 提交于 2020-01-09 04:18:05
问题 This page - http://labs.qt.nokia.com/2011/10/28/rpath-and-runpath/ - says about order for library search in ld.so: Unless loading object has RUNPATH: RPATH of the loading object, then the RPATH of its loader (unless it has a RUNPATH), ..., until the end of the chain, which is either the executable or an object loaded by dlopen Unless executable has RUNPATH: RPATH of the executable LD_LIBRARY_PATH RUNPATH of the loading object ld.so.cache default dirs And then suggest: When you ship binaries,