开发者

What kinds of libraries not needed to be specified in GCC?

I was wondering what kinds of libraries used in code ar开发者_Go百科e not needed to specify to gcc command? Is /usr/lib/libc.a the only one?

What kinds of libraries are needed to specify to gcc?

Thanks and regards!


You can get an idea of what arguments gcc automatically passes to the linker by using the -dumpspecs switch. For example, on my Windows 7 setup with MinGW using:

gcc -dumpspecs | less 

under libgcc section it shows:

*libgcc:
%{mthreads:-lmingwthrd} -lmingw32  %{shared-libgcc:-lgcc_s} -lgcc -lmoldname -lmingwex -lmsvcrt

which suggest those libraries are passed to the ld linker unless I explicitly forbid it with options like nodefaultlibs or nostdlib. Your gcc dumpspec will look different depending on the host-platform, OS and target it was configured to work with.

Edit: To help answer the questions in Tim's comment.

According to the gcc docs the meaning of the spec strings lib and libgcc are as follows:

 lib          Libraries to include on the command line to the linker
 libgcc       Decides which GCC support library to pass to the linker

As I understand it, both lib and libgcc are passed to the linker by default. This next part I'm not too sure about, so someone please correct if I'm wrong, if options like nodefaultlib get passed in then only the lib spec string will be applied but the libgcc won't.

I just checked the dumpspec for gcc 4.4.x on Ubuntu running under virtual-box and it appears the libc library gets included under the lib spec string.

*lib:
%{pthread:-lpthread}    %{shared:-lc}    %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}

Hope that answers your question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜