automatic-linking-tool - A simple command line tool to check Mach-O binary configuration for automatic linking
Recent Apple's ld(1)
and clang(1)
or swiftc(1)
supports automatic linking that embeds required linker flags into Mach-O binary file by parsing @import
or import
module syntax in the source code and eliminates -framework
or -l
linker flags when linking these object files.
However, when linking the project that has both Swift and Objective-C objects, it may be in trouble with unexpected linker flags or missing necessary linker flags caused by the automatic linking.
This command checks the object file to look up all such implicit linker options to investigate the actual linker options given to ld(1)
.
Equivalent command is like otool -l | grep -A 4 LC_LINKER_OPTION
.
automatic-linking-tool <file>
-
file
Path to the Mach-O binary file. Required.
The output is formatted in JSON structure, which is formatted in next syntax.
{
"is_swift_object": true,
"automatic_linking_options": [
"-lswiftFoundation",
...
]
}
You can aggregate these results per object type by using your favorite scripting tools.
Also, there is some useful but undocumented flags to control automatic linking behavior.
ld(1)
has -ignore_auto_link
that ignores all these linker options embedded in the object files.
clang(1)
has -fno-autolink
that disables embedding linker options to the object files and -fobjc-link-runtime
that enables embedding Objective-C runtime linker options like -framework Foundation
.
swiftc(1)
has -disable-autolink-framework <framework>
that disables embedding a specific -framework
linker option, but there are no options that completely disable automatic linking.
ld(1)
, clang(1)
, swiftc(1)