开发者

Get the default link configuration gcc uses when calling the linker

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?


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜