C语言 Mac OS X 上的标准 C 库在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6240639/
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
Where is the standard C library on Mac OS X?
提问by Oliver
I am trying to find the standard C library on Mac OS X. I've tried paths like: "/usr/lib/libc.a" or "/usr/lib/libm.a" , but there are no such files on the system. Could you tell me where to find it?
我试图在 Mac OS X 上找到标准的 C 库。我试过这样的路径: "/usr/lib/libc.a" 或 "/usr/lib/libm.a" ,但没有这样的文件系统。你能告诉我在哪里可以找到吗?
Then I used Terminal at a Linux machine and run such command:
然后我在 Linux 机器上使用终端并运行这样的命令:
ar t /usr/lib/libc.a
It returns a list of .o files and those .o files are like these:
它返回一个 .o 文件列表,这些 .o 文件如下所示:
svc.o
xdr.o
...
What are the meanings of these files? where to find them?
这些文件的含义是什么?在哪里可以找到它们?
回答by Stephen Canon
The standard library is part of libSystem.dylib on OS X.
标准库是 OS X 上 libSystem.dylib 的一部分。
回答by Jonathan Leffler
It looks like it is:
看起来是这样的:
/usr/lib/libSystem.B.dylib
on my machine (MacOS X 10.6.7).
在我的机器上(MacOS X 10.6.7)。
You can find out using otool— this is on a Mac running macOS 10.14.2 Mojave, and the (very simple) program was built using Clang from XCode:
您可以使用otool——这是在运行 macOS 10.14.2 Mojave 的 Mac 上找到的,并且(非常简单的)程序是使用 XCode 中的 Clang 构建的:
$ otool -L al
al:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
$ clang --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$
Other programs have more libraries. For example, this Tower of Hanoi program was built with a home-built GCC 8.2.0 and the ncurseslibrary:
其他程序有更多的库。例如,这个河内塔程序是用自制的 GCC 8.2.0 和ncurses库构建的:
$ otool -L hanoi
hanoi:
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
/opt/gcc/v8.2.0/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
$
And another program uses still more:
另一个程序使用更多:
$ otool -L $(which sqlcmd)
/Users/jonathanleffler/bin/sqlcmd:
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
isqls09b.dylib (compatibility version 0.0.0, current version 0.0.0)
iasfs09b.dylib (compatibility version 0.0.0, current version 0.0.0)
igens09a.dylib (compatibility version 0.0.0, current version 0.0.0)
iosls09a.dylib (compatibility version 0.0.0, current version 0.0.0)
sobj4/igl4a304.dylib (compatibility version 0.0.0, current version 0.0.0)
sobj4/iglxa304.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
/opt/gcc/v8.2.0/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
$
And system programs may use other libraries and frameworks:
并且系统程序可能会使用其他库和框架:
$ otool -L $(which passwd)
/usr/bin/passwd:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1561.0.0)
/System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libpam.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
$ otool -L /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57740.51.2)
/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 888.51.1)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
$
There are many other jobs that can be done with otool— look at the man page.
还有许多其他工作可以完成otool- 查看手册页。
回答by datenwolf
To answer your second question: static libraries are kept in archive files, hence the .a. As such they are just containers for a bunch of files, just like ZIP, TAR, RAR, etc. minus any compression. Those files listed by the ar(stands for archive) utility are the original files packed into the archive. You could unpack it and get the original files.
回答您的第二个问题:静态库保存在存档文件中,因此.a. 因此,它们只是一堆文件的容器,就像 ZIP、TAR、RAR 等一样,没有任何压缩。ar(代表存档)实用程序列出的那些文件是打包到存档中的原始文件。您可以解压缩它并获取原始文件。
Static libraries are in stark contrast to dynamic libraries. A static library's contents are extracted by the linker and included into your program upon linking, as if they were just results of other compilation stages of your program's build process.
静态库与动态库形成鲜明对比。静态库的内容由链接器提取并在链接时包含到您的程序中,就好像它们只是程序构建过程中其他编译阶段的结果。
Dynamic libraries OTOH are not just archives of object files, but they're linked executables by itself and the dynamic linker maps them into the linking processes address space and adjusts the symbol tables to match the mapped address.
动态库 OTOH 不仅仅是目标文件的存档,而且它们本身是链接的可执行文件,动态链接器将它们映射到链接进程地址空间并调整符号表以匹配映射的地址。
回答by LimeRed
Actually it does exist at /usr/lib/system/libsystem_c.dylib.
实际上它确实存在于/usr/lib/system/libsystem_c.dylib.
You can verify that with: $ nm -gU /usr/lib/system/libsystem_c.dylib
您可以通过以下方式验证: $ nm -gU /usr/lib/system/libsystem_c.dylib
回答by duskwuff -inactive-
To answer the other half of your question, OS X does not generally use static libraries (.a). As such, there is no libc.a(or libSystem.a) on OS X.
要回答您问题的另一半,OS X 通常不使用静态库 ( .a)。因此,OS X 上没有libc.a(或libSystem.a)。

