ld

Order in which library directories are searched and linked

£可爱£侵袭症+ 提交于 2019-12-10 20:18:02
问题 I am having difficulty understanding the order in which directories are searched for linking to libraries. I have a CentOS6 system and 3 versions of gcc, 4.4.7, 4.7.2, 4.9.2. The system version is 4.4.7 and version 4.7.2 and 4.9.2 are modules. In /etc/ld.so.conf.d/ there two files, gcc-4.7.2.conf and gcc-4.9.2.conf which contain the paths to the 4.7.2 and 4.9.2 libraries. I created a simple C++ program, main.cpp #include <cstdio> #include <iostream> using namespace std; int main(void) { cout

does gcc link order affect speed of the program execution

♀尐吖头ヾ 提交于 2019-12-10 19:56:38
问题 I know the linkage order in gcc is important for symbols to be correctly determined; but now I am seeing a wierd speed issue on the resulting executable. I am linking objects and archieves as g++ -m32 a.o b.o ar1.a ar2.a -lm -lpthread -lcrypt -lz -pthread -o afast.out vs g++ -m32 a.o ar1.a b.o ar2.a -lm -lpthread -lcrypt -lz -pthread -o aslow.out The second version runs 2x slower. b.o is actually in the ar1.a archieve, but ar2.o has references to it, thus linker complains, thus I had to put

How to force the linker to honor object file order?

我的梦境 提交于 2019-12-10 17:54:43
问题 I'm catching a Valgrind finding on an uninitialized read. I know exactly where its coming from - its an empty std::string declared in a cpp file with static storage class. The object file that has the std::string 's storage allocation is listed first in the static archive. # string of interest is located in a.o LIBOBJS := a.o b.o c.o ... x.o y.o z.o library.a: $(LIBOBJS) $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(RANLIB) $@ In addition, I modified the link recipe to the following (I know it looks silly

loading multiple similar shared libraries on linux

拥有回忆 提交于 2019-12-10 17:23:45
问题 I am working on code that creates 'models'. A model is created from an XML file and part of its representation is, generated on the fly, C code. This C code is compiled, on the fly, into a shared library that is dynamically loaded (using POCO shared lib class). The shared library mainly contains small functions, and part of a models creation is to populate function pointers to these functions. All this works fine. However, creating several models, at the same time, causes problems. I believe

Class with virtual function, when derived from QObject, leads to linking error

巧了我就是萌 提交于 2019-12-10 17:17:45
问题 Following is the code that works fine class HttpService { public: virtual ~HttpService(); // implemented in .cpp protected: HttpService(struct MHD_Connection *conn) {} }; class HttpFileService : public HttpService { public: virtual ~HttpFileService() ; // implemented in .cpp protected: HttpFileService(struct MHD_Connection *conn) : HttpService(conn) {} }; Now, when I make HttpService a derived class of QObject , like below: #include <QObject> // change #1 class HttpService : public QObject {

How does gcc/ld find zlib.so?

扶醉桌前 提交于 2019-12-10 16:52:18
问题 I've used zlib for ages and never thought about the fact that it is named slightly unconventionally. While most libraries on Linux follow the naming convention of lib<name>.so for shared objects and lib<name>.a for archives, zlib is named zlib.so / zlib.a . My question is: how does gcc/ld know to look for zlib.so when I use -lz as a link flag? I understand that for linking, gcc invokes ld, which searches for libraries in certain default paths and any path specified with -L , and it appends

Is there a linker flag to force it to load all shared libraries at start time?

痞子三分冷 提交于 2019-12-10 15:59:45
问题 Is there a flag or any other directive that I can use to force the Linux Dynamic Linker ld.so to load all shared libraries at once at start of the program instead of lazy binding. Essentially I want to turn off lazy binding. Thanks 回答1: Setting environment variable LD_BIND_NOW = 1 will do that. Thanks to @skwllsp for the answer. 回答2: man ld sayes: -z keyword now - When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is

GCC behavior for unresolved weak functions

≯℡__Kan透↙ 提交于 2019-12-10 15:45:32
问题 Consider the simple program below: __attribute__((weak)) void weakf(void); int main(int argc, char *argv[]) { weakf(); } When compiling this with gcc and running it on a Linux PC, it segfaults. When running it on ARM CM0 (arm-none-eabi-gcc), the linker replace the undefined symbol by a jump to the following instruction and a nop. Where is this behavior documented? Is there possible ways to change it through command line options? I have been through GCC and LD documentations, there is no

ld: xx duplicate symbols for architecture armv7 Xcode Project

蹲街弑〆低调 提交于 2019-12-10 14:14:09
问题 Hi everybody I have a Xcode project that gives me this error every time I try to build the project: ld: xx duplicate symbols for architecture armv7 Xcode Project clang: error: linker command failed with exit code 1... I have googled around and most solutions say to get rid of duplicate files in the build phase->Compile Resources section of the project or to change the import .m to .h in some files. Problem is the list of compiled resources isn't even sorted and I do not even know which files

How to remove warning: link.res contains output sections; did you forget -T?

眉间皱痕 提交于 2019-12-10 13:52:51
问题 I'm using fpc compiler and I want to remove this warning. I've read fpc's options but I can't find how to do that. Is this possible? it appear when I run command: fpc foo.pas out: Target OS: Linux for i386 Compiling foo.pas Linking p2 /usr/bin/ld: warning: link.res contains output sections; did you forget -T? 79 lines compiled, 0.1 sec 回答1: It's a bug in certain LD versions. Just ignore it for now, or see if your distro has an update for your LD. (package binutils) http://www.freepascal.org