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
313
votes
4 answers

I don't understand -Wl,-rpath -Wl,

For convenience I added the relevant manpages below. My (mis)understanding first: If I need to separate options with ,, that means that the second -Wl is not another option because it comes before , which means it is an argument to the -rpath…
Blub
  • 13,014
  • 18
  • 75
  • 102
286
votes
2 answers

What's the difference between .so, .la and .a library files?

I know an .so file is a kind of dynamic library (lots of threads can share such libraries so there is no need to have more than one copy of it in memory). But what is the difference between .a and .la? Are these all static libraries? If dynamic libs…
hugemeow
  • 7,777
  • 13
  • 50
  • 63
206
votes
4 answers

LD_LIBRARY_PATH vs LIBRARY_PATH

I'm building a simple C++ program and I want to temporarily substitute a system supplied shared library with a more recent version of it, for development and testing. I tried setting the LD_LIBRARY_PATH variable but the linker (ld) failed…
Georgios Politis
  • 2,610
  • 3
  • 19
  • 10
200
votes
6 answers

How to print the ld(linker) search path

What is the way to print the search paths that in looked by ld in the order it searches.
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
170
votes
21 answers

How to fix linker error "cannot find crt1.o"?

I have a virtual Debian system which I use to develop. Today I wanted to try llvm/clang. After installing clang I can't compile my old c-projects (with gcc). This is the error: /usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld:…
Stefan Keller
  • 1,703
  • 2
  • 11
  • 5
151
votes
13 answers

How to remove unused C/C++ symbols with GCC and ld?

I need to optimize the size of my executable severely (ARM development) and I noticed that in my current build scheme (gcc + ld) unused symbols are not getting stripped. The usage of the arm-strip --strip-unneeded for the resulting executables /…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
127
votes
7 answers

What does "collect2: error: ld returned 1 exit status" mean?

I see the error collect2: error: ld returned 1 exit status very often. For example, I was trying to build the following snippet of code: void main() { char i; printf("ENTER i"); scanf("%c", &i); clrscr(); switch(i) { default: …
user3682120
  • 1,273
  • 2
  • 9
  • 4
115
votes
1 answer

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

The GNU Compiler Collection (aka gcc) and ld provide many ways to specify a search path for libraries—among them the -rpath and -L flags. The manpages reveal no differences between these two flags, effectively saying each flag adds a library to the…
Craig M. Brandenburg
  • 3,354
  • 5
  • 25
  • 37
101
votes
1 answer

What are the --start-group and --end-group command line options?

What is the purpose of those command line options? Please help to decipher the meaning of the following command line: -Wl,--start-group -lmy_lib -lyour_lib -lhis_lib -Wl,--end-group -ltheir_lib Apparently it has something to do with linking, but…
pic11
  • 14,267
  • 21
  • 83
  • 119
98
votes
2 answers

combine two GCC compiled .o object files into a third .o file

How does one combine two GCC compiled .o object files into a third .o file? $ gcc -c a.c -o a.o $ gcc -c b.c -o b.o $ ??? a.o b.o -o c.o $ gcc c.o other.o -o executable If you have access to the source files the -combine GCC flag will merge the…
Lucian Adrian Grijincu
  • 2,491
  • 2
  • 18
  • 18
86
votes
1 answer

How to get the size of an input section (to place it at the end of memory)

I have the following linker script: .data & .bss are placed into ram, then a .heap section fills the remaining memory. Now I want to add a .noinit section that always gets placed at the end of the memory. That is so it gets ignored by bootloaders…
user1273684
  • 1,559
  • 15
  • 24
82
votes
3 answers

ld: library not found for -lcrt0.o on OSX 10.6 with gcc/clang -static flag

When I try to build the following program: #include int main(void) { printf("hello world\n"); return 0; } On OS X 10.6.4, with the following flags: gcc -static -o blah blah.c It returns this: ld: library not found for…
browneye
  • 821
  • 1
  • 6
  • 3
81
votes
3 answers

Why does the order of '-l' option in gcc matter?

I am trying to compile a program which uses udis86 library. Actually I am using an example program given in the user-manual of the library. But while compiling, it gives error. The errors I get are: example.c:(.text+0x7): undefined reference to…
user1129237
76
votes
5 answers

How to set the LDFLAGS in CMakeLists.txt?

I set the CFLAGS in CMake by CMAKE_C_FLAGS. Is something like this to set LDFLAGS?
hich9n
  • 1,578
  • 2
  • 15
  • 32
69
votes
3 answers

What is the difference between -I and -L in makefile?

What is the usage of the -I and -L flags in a makefile?
MainID
  • 29,070
  • 19
  • 57
  • 70
1
2 3
99 100