Use dyld to link in frameworks at runtime. Use ld to make your programs and link archive libraries at build time.

Posts under Linker tag

160 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Xcode 15.0.1 and Xcode 15.1 breaking changes when using link time optimization (works in Xcode 15.0)
The following is occurring when linking a release version of our test suite. 0 0x102d82f9c __assert_rtn + 72 1 0x102d36e08 mach_o::Symbol ld::Layout::symbolForAtom<ld::LinkedAtomPlacement const>(ld::Atom const*, CString, ld::LinkedAtomPlacement const&, ld::DylibMapping const*, unsigned long long) const + 2120 2 0x102d36ff8 void dispatchForEach<ld::AtomAndName const, void ld::buildSymbolTableld::LinkedAtomPlacement(ld::SymbolTableLayout&, ld::Layout const&, ld::Options const&, ld::AtomSymbolPartition const&, ld::LinkedAtomPlacement const&, ld::DylibMapping const*, unsigned long long, bool, bool)::'lambda1'(unsigned long, ld::AtomAndName const&)>(std::__1::span<ld::LinkedAtomPlacement, 18446744073709551615ul>, unsigned long, void ld::buildSymbolTableld::LinkedAtomPlacement(ld::SymbolTableLayout&, ld::Layout const&, ld::Options const&, ld::AtomSymbolPartition const&, ld::LinkedAtomPlacement const&, ld::DylibMapping const*, unsigned long long, bool, bool)::'lambda1'(unsigned long, ld::AtomAndName const&))::'lambda'(unsigned long)::operator()(unsigned long) const + 152 3 0x102d3f17c ld::LayoutExecutable::writeToFile(char const*) + 5004 4 0x102cf362c main + 9604 ld: Assertion failed: (0 && "lto symbol should not be in layout"), function symbolForAtom, file Layout.cpp, line 1447.
1
1
608
Nov ’23
Xcode 15 Error: ld: Assertion Failed
I am writing to report an issue that I've encountered while using Xcode 15 to compile an iOS 17 project. The error message I received is as follows: ld: Assertion failed: (false && "compact unwind compressed function offset doesn't fit in 24 bits"), function operator(), file Layout.cpp, line 5758. At present, the exposure path of this problem seems to be here: "Xcode.app-strings/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /ld". I want to bring to your attention that this issue has been persistent from beta 6 to the official release of Xcode 15. I have already submitted a bug report with the identifier FB13321572. I am keen to leverage the new feature "ld-prime" and would greatly appreciate your guidance and support in finding an elegant solution to address this problem.(The implication is that I don't really want to continue using ld64 linker ...lol) Thanks
1
0
1.6k
Nov ’23
Load a library with LC_LOAD_DYLIB instead of LC_LOAD_WEAK_DYLIB
Hello, I have create a dynamic library with gcc: gcc -dynamiclib liblib1.c -o liblib1.dylib I have create a binary which needs this dynamic library: gcc -L./ -llib1 test.c -o test I have looked at mach-o commands in test binary. I have seen the library is loaded with LC_LOAD_WEAK_DYLIB. How can i load the library with LC_LOAD_DYLIB instead of LC_LOAD_WEAK_DYLIB ? And i have a second question: Is it possible to compile the binary with a static linking of the library ? I have tried with -static option, like i do on Linux but it does not work on macOS and i don't understand why... Thanks
1
0
741
Nov ’23
G++ not working with command line tools 15.0 and not able to downgrade its version on MacOS Sonoma.
I am not able to install after downloading command line tools 14.3.1 in macOS Sonoma 14.0. The error message is the following "Command Line Tools can't be installed on this disk (Macintosh HD). The version of macOS is too new." What should I do to install it ? And what to do after that so that 14.3.1 version is used by Mac instead of 15.0 version of command line tools ?
3
0
798
Nov ’23
Error during archive
Good Morning, I get this error every time I try to make the archive and I don't see any more information, nor have I found a solution, could you please help me to solve it? ld: building for 'iOS', but linking in object file (/Users/juanjo/Documents/Jabali/platforms/ios/build/Debug-iphonesimulator/XCFrameworkIntermediates/GoogleAppMeasurement/WithoutAdIdSupport/GoogleAppMeasurement.framework/GoogleAppMeasurement[arm64][3](apm_experimentation .pb.o)) built for 'iOS-simulator' clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
0
499
Oct ’23
"GOT load reloc does not point to a LDR instruction" - XCode 15 linking issue
Hi all, I've inherited a legacy project I've been working to clean up and have run into a new issue trying to build with XCode 15. The project builds to simulator using rosetta but any attempt to build to devicefails. It built fine with XCode 14 so I'm assuming something changed in 15 but I have no idea where to look. It seems to build all of the subprojects successfully and then it gets to Build Target AppName, completes several steps, and errors on 'Link <ProjectName (arm64)' with the errors: ld: warning: ignoring duplicate libraries: '-lc++', '-lsqlite3', '-lz' ld: GOT load reloc does not point to a LDR instruction in _aom_highbd_sad64x16_avg_c If anybody could suggest even a starting point for unpacking this I'd be deeply grateful!
6
0
1.2k
Oct ’23
Invalid use of branch fixup with Xcode 15
Hello! I originally mentioned this issue here and was advised to start a new thread and tag it with Linker, so I did. The problem is that when using Xcode 15 to build my code, I'm getting this link error: Currently this issue is preventing us to move to using Xcode 15. Xcode 14.3 can build our code correctly. So far our investigation brought us to either disable LTO for our project (which is not good, as our codebase heavily relies on interprocedural optimizations offered by the LTO), or to add flags -Wl,-ld_classic -Wl,-mllvm,-opaque-pointers to our linker. We currently opted for the second option for mac builds, while iOS builds don't recognize -ld_classic flag. However, since the classic LD64 is scheduled to be removed in a future update, we will need to find a more permanent solution. The build issue affects both Mac and iOS builds.
2
0
876
Oct ’23
[Xcode 15] Unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in libLLVM.dylib
After upgrading my Xcode from 14.3 to 15.0, there is a compilation error "Unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in libLLVM.dylib". There is no solution found anywhere (Google, Stackoverflow, This forum). The error message is not helpful to locate the root cause. I also tried to read through this page https://iphonedev.wiki/Mach-O_File_Format to know more about LLVM, MH_OBJECT. So far, i cannot find any good reference.
7
0
2.5k
Oct ’23
xcode15 ld: Assertion failed: (extras.otherInstrOffset != 0 && "Kind::arm64_adrp_ldr missing extra info")
When I upgrade to xcode15, I get an error compiling the project with the following error message 0 0x104f5f648 __assert_rtn + 72 1 0x104e87c5c ld::Fixup::applyFixup(ld::Atom const*, ld::LayoutLinkedImage const&amp;, unsigned char*) const + 8268 2 0x104f1a7d8 ___ZN2ld16LayoutExecutable27writeContentWithoutLinkEditENSt3__14spanIhLm18446744073709551615EEEy_block_invoke + 332 3 0x18c39b950 _dispatch_client_callout2 + 20 4 0x18c3b01a4 _dispatch_apply_invoke_and_wait + 176 5 0x18c3af464 _dispatch_apply_with_attr_f + 1176 6 0x18c3af650 dispatch_apply + 96 7 0x104f1a9e4 void mapReduce&lt;ld::Atom const*, mach_o::Error&gt;(std::__1::span&lt;ld::Atom const*, 18446744073709551615ul&gt;, unsigned long, void (unsigned long, mach_o::Error&amp;, std::__1::span&lt;ld::Atom const*, 18446744073709551615ul&gt;) block_pointer, void (std::__1::span&lt;mach_o::Error, 18446744073709551615ul&gt;) block_pointer) + 336 8 0x104f1a594 ld::LayoutExecutable::writeContentWithoutLinkEdit(std::__1::span&lt;unsigned char, 18446744073709551615ul&gt;, unsigned long long) + 1180 9 0x104f20020 ld::LayoutExecutable::writeToFile(char const*) + 15248 10 0x104ed22e8 main + 9424 ld: Assertion failed: (extras.otherInstrOffset != 0 &amp;&amp; "Kind::arm64_adrp_ldr missing extra info"), function applyFixup, file Fixup.cpp, line 793. clang: error: linker command failed with exit code 1 (use -v to see invocation) This error only occurs when archiving, not when building. I don't get this error when I delete the C++ code in the project. How do I solve it?
4
1
764
Oct ’23
ld: symbol(s) not found for architecture arm64
Hi,all I'm writing a simple c program on my m1 MacBook with vscode ,but when I complied the project, error occurs: Undefined symbols for architecture arm64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) I installed Xcode and used vscose and my program is : #include <cstdio> int main() { char name[100];printf("please input your name:"); scanf("%s",name); printf("hello,%s",name); }
7
2
21k
Oct ’23
Xcode 15 linking error
Hi, I am getting a linking error when building my app to run against an iOS17 device, using Xcode15. Same project builds and runs fine with Xcode 14 and iOS16. The linking error just says: clang: error: unable to execute command: Segmentation fault: 11 clang: error: linker command failed due to signal (use -v to see invocation) Not sure what I should try to overcome this. I can't run my app on an iOS17 device. It builds, links and runs just fine on a simulator.
28
16
21k
Oct ’23
how to inhibit -fprofile-instr-generate passed to linker
I'm struggling to build a driver for iPadOS in a particular project configuration. If I put the driver code and dext target into the same Xcode project which contains the iPad app, all is well. This is the way the Xcode driver template does it. However, I'd like to build and debug the dext on macOS, while eventually deploying on iPadOS. So I put the dext into a different project, which has a macOS target, a minimal iPadOS target and a DriverKit target. I made a workspace which contains both projects. I dragged the macOS project into the iPadOS project so that I can refer to the products of the macOS project (specifically, its driver target) as a dependency of the iPadOS target. Note that the main iPad app target depends on the driver target. So the workspace organization looks like this: Workspace iPad project main iPad app target (depends on driver) test project reference test project test macOS/iPad app target DriverKit dext target When I build the iPadOS target, it builds the dependent driver target in the macOS project, but it fails to link because Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.profile_driverkit.a is not found. If I just build the driver target directly in Xcode, there is no such complaint. I looked closely at the build logs, and I see for the failed link, there are these two linker flags set which are not set in the successful case -debug_variant -fprofile-instr-generate I can't seem to control the generation of this flag. I tried turning off the Profile switch in the Scheme editor for the driver, but is makes no difference. When I directly build the driver target, no -fprofile-instr-generate is set and it compiles and links. When i build the driver as a dependency of another target, -fprofile-instr-generate is passed to the linker, which fails. The obvious workaround is to put the driver source code into a separate driver target in the iPadOS project, but I'd rather have just one DriverKit driver for both platforms, with a few settings (such as bundle ID) controlled by a configuration file. Has anyone else encountered this problem, and know of a workaround?
1
0
636
Oct ’23
Xcode 15: linking failed due to missing file.
Hey! Since updating to Xcode 15 we experience problems while archiving our app. We have linked several Swift Packages to our NotificationSerivceExtension which are needed to handle incoming notifications. We tried different approaches to solve this problem, including setting the -ld_classic linker flag. ld: file not found: /Users/Daniel/Library/Developer/Xcode/DerivedData/APP-gujhwevhlpoiyteeiandolhxwgqx/Build/Intermediates.noindex/ArchiveIntermediates/APP/BuildProductsPath/AdHoc-iphoneos/UserNotificationService.o clang: error: linker command failed with exit code 1 (use -v to see invocation) This blocks us to updating to Xcode 15 and Sonoma :(.
1
0
602
Oct ’23
Duplicate symbols when linking a static library containing Objective-C++
ld_prime of Xcode 15 produces duplicate symbols when linking a static library containing Objective-C++ object in case using the flags -ObjC and -Wl,force_load. // foo.h #pragma once int Inc(int i); // foo.mm #include "foo.h" #include <Foundation/Foundation.h> @interface Foo : NSObject @end @implementation Foo @end int Inc(int i) { return i + 1; }; // main.cpp #include "foo.h" int main(int argc, const char * argv[]) { return Inc(0); } ❯ clang++ -c foo.mm ❯ ar rcs libfoo.a foo.o ❯ clang++ -framework Foundation libfoo.a -x c++ main.cpp -Wl,-force_load,libfoo.a -ObjC duplicate symbol '__Z3Inci' in: libfoo.a[2](foo.o) libfoo.a[2](foo.o) duplicate symbol '_OBJC_CLASS_$_Foo' in: libfoo.a[2](foo.o) libfoo.a[2](foo.o) duplicate symbol '_OBJC_METACLASS_$_Foo' in: libfoo.a[2](foo.o) libfoo.a[2](foo.o) ld: 3 duplicate symbols clang: error: linker command failed with exit code 1 (use -v to see invocation)```
4
0
1.9k
Oct ’23
Xcode 15 linker error: not 8-byte aligned, which cannot be encoded as a target of LDR/STR
In an old project we just moved on mac ARM + Sonoma + Xcode 15 (fresh install), we get this link error: '_yytext' from '.../Objects-normal/arm64/html.lexer.o' not 8-byte aligned, which cannot be encoded as a target of LDR/STR in '_PHPyylex' from '.../Objects-normal/arm64/php.lexer.o' We don't get this error on Xcode 15 on mac Intel, nor with Xcode 14 on mac ARM. Does anyone know what we could do to fix that? thanks!
4
0
639
Oct ’23
Why dlopen failed on some macOS
Hi All: I use dlopen to load a dylib on macOS, It woks fine. Recently, I received one customer report bug, After checked the log, I found that dlopen failed on customer's environment(macOS 13.5.2 22G91) as below load xxxx failed: dlopen(/***/yyy/zzz.dylib, 0x0001): tried: '/***/yyy/zzz.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/***/yyy/zzz.dylib' (no such file), '/***/yyy/zzz.dylib' (no such file) I use full file path to dlopen dylib, and the file is located at there I checked dylib signature, notarization, dependency frameworks, all are valid I got copy and replace customer's dylib into myself environment, It woks fine Customer tried several mac computers, others do not have this problem I am confused about this issue and do not know how to investigate further. Any comments is appreciated.
5
0
1k
Oct ’23