3

I am using the CodeSorcery arm-eabi-gcc tool chain and I have a problem using ld separate from gcc

I can compile my simple program and link it, if I let gcc call the ld.

This works not problem

g++ test.cpp; # Works

This does not work because of missing symbols

g++ -c test.cpp

ld -o test crti.o crtbegin.o test.o crtend.o crtn.o -lgcc -lc -lstdc++; # Fails

Notice I am adding the gcc libraries to the ld command

What am I missing?

Also if there is a better way to make configuring ld to using the default gcc linking?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Ted
  • 14,465
  • 6
  • 28
  • 28

2 Answers2

4

The easiest way is to have gcc/g++ drive a separate link:

g++ -c test.cpp      # compile
g++ -o test test.o   # separate link

If you need to pass linker options, you can use -Wl:

g++ -o test test.o -Wl,-somelinkeroption,arg
R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
4

@R Samuel Klatchko has the best advice, but if you really want to see what gcc/g++ is linking in use the -v verbose option.

It displays the full directory paths used to search for header files and libraries, the predefined preprocessor symbols, and the object files and libraries used for linking.

zdav
  • 2,752
  • 17
  • 15