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
42
votes
1 answer

Is there a difference between the "-Wl,option" and "-Xlinker option" syntax for GCC?

I have been looking through some configuration files and I've seen both being used (albeit on different architectures). If you're using GCC on a Linux box, is there a difference between the two syntaxes for passing options to the linker? Reading the…
bpw1621
  • 2,962
  • 2
  • 32
  • 35
41
votes
1 answer

what is the difference between ranlib, ar, and ld for making libraries

To make libraries in c++/unix from *.o files, I have noticed two different ways in my project (legacy code): ar qc libgraphics.a *.o ranlib libgraphics.a and ld -r -o libgraphics.a *.o What is the difference between the two approaches, and which…
R71
  • 4,283
  • 7
  • 32
  • 60
41
votes
4 answers

What is global _start in assembly language?

This is my assembly level code ... section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, mesg mov edx, size int 0x80 exit: mov eax, 1 int 0x80 section .data mesg db 'KingKong',0xa size …
vikkyhacks
  • 3,190
  • 9
  • 32
  • 47
39
votes
3 answers

Resolving circular dependencies by linking the same library twice?

We have a code base broken up into static libraries. Unfortunately, the libraries have circular dependencies; e.g., libfoo.a depends on libbar.a and vice-versa. I know the "correct" way to handle this is to use the linker's --start-group and…
Nemo
  • 70,042
  • 10
  • 116
  • 153
39
votes
2 answers

What is a C++ "Key Function" as described by gold?

Please do not answer the question "how do I solve this error message?" In the error message provided by gold: /usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function What is a key function? I find…
Cuadue
  • 3,769
  • 3
  • 24
  • 38
39
votes
3 answers

How can I force linking with a static library when a shared library of same name is present

Suppose I have a file main.cpp which uses sin() function which is defined in libmath. Also suppose that we have both libmath.a and libmath.so available in the same directory. Now if I issue the command g++ -o main main.cpp -lmath the default…
user550009
  • 391
  • 1
  • 3
  • 3
38
votes
9 answers

dlopen from memory?

I'm looking for a way to load generated object code directly from memory. I understand that if I write it to a file, I can call dlopen to dynamically load its symbols and link them. However, this seems a bit of a roundabout way, considering that it…
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
38
votes
2 answers

Segfault on declaring a variable of type vector>

Code Here is the program that gives the segfault. #include #include #include int main() { std::cout << "Hello World" << std::endl; std::vector> y {}; std::cout << "Hello World" <<…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
38
votes
4 answers

How do I determine the fastest link order?

I have about 50 different static libraries being linked into my c++ project and the linking takes on average 70s. I've found that moving around with the link order of the libraries changes this time. This is expected I guess if the linker doesn't…
owagh
  • 3,428
  • 2
  • 31
  • 53
34
votes
2 answers

GCC how to add before the default linker search path by default? LIBRARY_PATH not working

I'm trying to figure out how to set some environment variable which would make g++ to link to correct versions of the libraries. I have some old boost libraries in /usr/lib64 (linking against these will fail) and new libraries in /v/users/regel/lib.…
Regel
  • 607
  • 1
  • 6
  • 11
34
votes
1 answer

How to get GCC linker command?

How can I get the command line GCC uses to invoke ld? I have a problem for an AVR target where GCC apparently adds a linker option which I am trying to override, so I would like to look at the exact options GCC uses for ld.
user143579
33
votes
4 answers

error while loading shared libraries: libboost_system.so.1.45.0: cannot open shared object file: No such file or directory

I am building a C++ executable on Linux. The executable links into some boost libraries. This is the output when I attempt to run the binary: root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ./testfgci ./testfgci: error while…
skyeagle
  • 3,211
  • 11
  • 39
  • 41
33
votes
3 answers

How to make gcc link strong symbol in static library to overwrite weak symbol?

My problem can be summarised in the following: bar.c: #include void bar() { printf("bar\n"); } main.c: #include void __attribute__((weak)) bar() { printf("foo\n"); } int main() { bar(); return…
user1777342
  • 433
  • 1
  • 5
  • 11
32
votes
4 answers

Strange warnings from the linker (ld)

We are building a Mac OSX application which is written mostly in Obj-C/Cocoa. The application then statically links with some 3rd party libraries, written in C/C++ and compiled by us (on a command line, using either MacPorts or the usual…
ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69
31
votes
1 answer

undefined reference to `log'

I am trying to compile the implementation of the RFC 3797 random selection algorithm by Donald Eastlake (code: http://kambing.ui.ac.id/minix/other/rfc3797/). However, I am getting a linker error: rfc3797.c:(.text+0xe7f): undefined reference to…
Shade
  • 9,936
  • 5
  • 60
  • 85