macos gcc 链接的默认库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11481154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 09:20:04  来源:igfitidea点击:

Default libraries linked in by gcc?

c++clinuxmacosgcc

提问by user1516425

Let's say I have a very simple C file (called foo.c):

假设我有一个非常简单的 C 文件(称为 foo.c):

int main()
{
   printf("foo");
   return 0;
}

Now I call gcc:

现在我调用 gcc:

gcc foo.c

When I call gcc (with no options, as in the above example), what libraries are linked in by default and where are they located? (On Mac OS X 10.7)

当我调用 gcc(没有选项,如上例所示)时,默认链接哪些库以及它们位于何处?(在 Mac OS X 10.7 上)

回答by Michael Burr

The -voption to gccwill cause it to dump information about the default options it will use including the library paths and default libraries and object files that will be linked in.

-v选项gcc将导致它倾倒它会使用包括图书馆的路径和默认的库文件和目标文件将在被链接的默认选项的信息。

If you give the -Wl,--verboseoption, gcc will pass the --verboseto the linker which will dump exactly where it's looking for libraries, including both failed and successful searches.

如果您提供该-Wl,--verbose选项,gcc 会将 传递--verbose给链接器,链接器将准确地转储它正在寻找库的位置,包括失败和成功的搜索。

Combine both options, and you'll see exactly what libraries are linked in, and why they're being linked in.

结合这两个选项,您将确切地看到链接了哪些库,以及为什么要链接它们。

gcc -v foo.c -Wl,--verbose

回答by bhuwansahni

The standard libraries are linked by default. they are located in /usr in linux machines

默认情况下链接标准库。它们位于 linux 机器的 /usr 中