Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

macos - What actually happens when I add libcurl.4.tbd as a dependency in xcode?

When I want to add libcurl as a dependency I add libcurl.4.tbd under Link Binary with Libraries and it works. As I understand it these tbd files are stub libraries to enable the linking process for dynamic libraries while keeping the Xcode SDK download small (by replacing the actual dylib with a kind of placeholder).

When I open the libcurl.4.tbd in Xcode, it lists under install-name /usr/lib/libcurl.4.dylib and I expected to find this file. But I can't find the actual libcurl.4.dylib at this dir nor anywhere else on my system. otool -L gives me same filepath.

How is the linking handled in this case and where is the actual dylib located? I'm running macOS 11.1

question from:https://stackoverflow.com/questions/65842584/what-actually-happens-when-i-add-libcurl-4-tbd-as-a-dependency-in-xcode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

All the built-in libraries ship in one big cache file on macOS (at least in Big Sur, not sure on earlier systems) and iOS (since iPhone OS 3.1). More information is available in the iPhone Dev Wiki.

To find the actual location of the cache on your machine, run your compiled executable with the DYLD_PRINT_SEGMENTS environment variable set. This will produce a lot of output on stderr, like this:

% DYLD_PRINT_SEGMENTS=1 ./your_executable
re-using existing shared cache (/System/Library/dyld/dyld_shared_cache_x86_64h):
        0x7FFF2003B000->0x7FFF7FFBAFFF init=5, max=5 read execute 
        0x7FFF8003B000->0x7FFF8DFDEFFF init=3, max=3 read write data
        0x7FFFC003B000->0x7FFFE22DAFFF init=1, max=1 read 
dyld: Main executable mapped /Users/janten/Desktop/linky/./a.out
        __PAGEZERO at 0x00000000->0x100000000
            __TEXT at 0x106305000->0x106309000
      __DATA_CONST at 0x106309000->0x10630D000
            __DATA at 0x10630D000->0x106311000
        __LINKEDIT at 0x106311000->0x106315000
dyld: Using shared cached for /usr/lib/libcurl.4.dylib
            __TEXT at 0x7FFF32F8F000->0x7FFF32FF5000
            __DATA at 0x7FFF89A67070->0x7FFF89A6A04C
        __LINKEDIT at 0x7FFFC05FF000->0x7FFFDEF17CB0
...

In this example, the cache is located in /System/Library/dyld/dyld_shared_cache_x86_64h. If you want to see the complete content of this file, look at /System/Library/dyld/dyld_shared_cache_x86_64h.map, which contains a plain-text memory mapping for all libraries in the cache.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...