Questions tagged [ld]

The ld (linker or loader) program combines object files, archive files and (references from) shared libraries, relocates their data and addresses together with symbol references. Linking is usually the final step of compiling a program.

2795 questions
66
votes
5 answers

Architecture of i386 input file is incompatible with i386:x86-64

I'm trying to create a simple kernel using Ubuntu. In the terminal I typed ld -Ttext 0x1000 -o kernel.bin loader.o main.o Video.o But I got the following error message in return: ld: i386 architecture of input file `loader.o' is incompatible with…
MEv2.0
  • 743
  • 2
  • 7
  • 8
65
votes
14 answers

linker error while linking boost log tutorial (undefined references)

I have installed boost on Fedora 20 via yum and am trying some simple examples. However I have trouble to compile the first example from the logging tutorial. Compiling with g++ -c boosttest.cc works fine, but I get lot's of errors when I try to…
Michael Große
  • 1,818
  • 1
  • 16
  • 20
64
votes
6 answers

The proper way of forcing a 32-bit compile using CMake

Sorry that there are many similar questions, but I do find that Googling for CMake queries always yields similar-but-not-the-same scenarios, conflicting CMake commands and so on! I need to force my project to build 32-bit binaries because I have to…
devrobf
  • 6,973
  • 2
  • 32
  • 46
60
votes
3 answers

What does KEEP mean in a linker script?

The LD manual does not explain what the KEEP command does. Below is a snippet from a third-party linker script that features KEEP. What does the KEEP command do in ld? SECTIONS { .text : { . = ALIGN(4); _text = .; …
Randomblue
  • 112,777
  • 145
  • 353
  • 547
54
votes
1 answer

install_name_tool to update a executable to search for dylib in Mac OS X

I have a dynamic libray libtest.dylib that is installed in /PATH/lib, and an execution binary, myapp, that uses the dylib installed in /PATH/bin. I can run myapp to find the dylib as follows (Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And,…
prosseek
  • 182,215
  • 215
  • 566
  • 871
53
votes
2 answers

What's the difference between `-rpath-link` and `-L`?

The man for gold states: -L DIR, --library-path DIR Add directory to search path --rpath-link DIR Add DIR to link time shared library search path The man for bfd ld makes it sort of sound like -rpath-link is used for…
lanza
  • 1,512
  • 2
  • 13
  • 26
52
votes
12 answers

Linking against older symbol version in a .so file

Using gcc and ld on x86_64 linux I need to link against a newer version of a library (glibc 2.14) but the executable needs to run on a system with an older version (2.5). Since the only incompatible symbol is memcpy (needing memcpy@GLIBC_2.2.5 but…
PlasmaHH
  • 15,673
  • 5
  • 44
  • 57
48
votes
7 answers

Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?

I have some code that uses some shared libraries (c code on gcc). When compiling I have to explicitly define the include and library directories using -I and -L, since they aren't in the standard places. When I try to run the code, I get the…
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
47
votes
2 answers

How to link C++ object files with ld

I'm trying to link the output of C++ using ld and not g++. I'm only doing this to learn how to do it, not for practical purposes, so please don't suggest just to do it with g++. Looking at this question, the person gets the same error when they run…
gsgx
  • 12,020
  • 25
  • 98
  • 149
46
votes
9 answers

Very strange linker behavior

This is strange because I was able to get the error below to go away by removing the reference to libm. gcc -o example example.o -Wl -L/home/kensey/cdev/lib -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -L/usr/lib/x86_64-linux-gnu -lm…
Don Wool
  • 1,147
  • 4
  • 13
  • 18
46
votes
12 answers

Xcode: ld: library not found for -lAFNetworking

Because of this one reason, build always fails...Any ideas about what I could try? EDIT: the solution is to open the xcworkspace instead of the xcproject!
Akbapu
  • 779
  • 2
  • 6
  • 14
46
votes
4 answers

Why does ld need -rpath-link when linking an executable against a so that needs another so?

I'm just curious here. I have created a shared object: gcc -o liba.so -fPIC -shared liba.c And one more shared object, that links against the former one: gcc -o libb.so -fPIC -shared libb.c liba.so Now, when creating an executable that links…
Troels Folke
  • 917
  • 2
  • 9
  • 12
46
votes
7 answers

GNU gcc/ld - wrapping a call to symbol with caller and callee defined in the same object file

to clarify, my question refers to wrapping/intercepting calls from one function/symbol to another function/symbol when the caller and the callee are defined in the same compilation unit with the GCC compiler and linker. I have a situation resembling…
luis.espinal
  • 10,331
  • 6
  • 39
  • 55
45
votes
4 answers

How to force gcc to link an unused static library

I have a program and a static library: // main.cpp int main() {} // mylib.cpp #include struct S { S() { std::cout << "Hello World\n";} }; S s; I want to link the static library (libmylib.a) to the program object (main.o), although…
Martin
  • 9,089
  • 11
  • 52
  • 87
43
votes
3 answers

Linker performance related to swap space?

Sometimes it's handy to mock up something with a little C program that uses a big chunk of static memory. I noticed after changing to Fedora 15 the program took a long time to compile. We're talking 30s vs. 0.1s. Even more weird was that ld…
Rooke
  • 2,013
  • 3
  • 22
  • 34