Skip to content

creating static libraries targeting macosx results in unusable .a files #1981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Feb 18, 2019 · 2 comments · Fixed by #2526
Closed

creating static libraries targeting macosx results in unusable .a files #1981

andrewrk opened this issue Feb 18, 2019 · 2 comments · Fixed by #2526
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Feb 18, 2019

export fn foo() void {}
zig build-lib foo.zig
void foo(void);
int main() {foo(); return 0;}
cc -o test test.c foo.a
ld: warning: ignoring file foo.a, file was built for archive which is not the architecture being linked (x86_64): foo.a

The error message is bogus; the file is of course the correct architecture.

Suggestion here is to use libtool -static -o libio.a io.o rather than ar.:
https://stackoverflow.com/questions/30948807/static-library-link-issue-with-mac-os-x-symbols-not-found-for-architecture-x8

We will have to figure out how to do that using LLVM API.

A workaround for this bug is to use build-obj instead of build-lib. Indeed that's the workaround here:

zig/src/link.cpp

Lines 35 to 42 in 74a335c

// The Mach-O LLD code is not well maintained, and trips an assertion
// when we link compiler_rt and builtin as libraries rather than objects.
// Here we workaround this by having compiler_rt and builtin be objects.
// TODO write our own linker. https://github.com/ziglang/zig/issues/1535
OutType child_out_type = OutTypeLib;
if (parent_gen->zig_target.os == OsMacOSX) {
child_out_type = OutTypeObj;
}

Related issue regarding a new linker: #1535
Related issue regarding dynamic libraries: #1982

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Feb 18, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Feb 18, 2019
@LemonBoy
Copy link
Contributor

// The Mach-O LLD code is not well maintained, and trips an assertion
// when we link compiler_rt and builtin as libraries rather than objects.

Is the assertion you get the same as #2421?

@andrewrk
Copy link
Member Author

I believe I was tripping

llvm_unreachable("bad reloc kind");
and some of the other equivalent assertions in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants