#what does addObjectFile do?

1 messages · Page 1 of 1 (latest)

molten birch
#

In my quest to get SDL working with zig, I am currently trying out this addObjectFile thing. It's looking like it is not simple to build SDL for iOS inside the zig ecosystem. So instead I am trying a prebuilt ios library.

const lib = b.addLibrary(.{
    .linkage = .static,
    .name = "cc-ios",
    .root_module = mod,
});
platform_setup(b, &target, lib);
lib.addObjectFile(b.path("libs/SDL3.xcframework/ios-arm64/SDL3.framework/SDL3.a"));
b.verbose_link = true;
b.installArtifact(lib);

I know that _SDL_Init is in there:

% nm libs/SDL3.xcframework/ios-arm64/SDL3.framework/SDL3.a | grep _SDL_Init
000000000011d67c T _SDL_Init

But after building it is clearly not linked.

% nm ios/cc/libcc-ios.a | grep _SDL_Init
                 U _SDL_Init

What am I missing. Can I get this prebuilt downloaded SDL3 library linked to my zig library using addObjectFile or am I misunderstanding something?

atomic pivot
#

can you confirm, that if you do zig build [...] --verbose, the library path is a command argument of a command that is printed.

molten birch
#

Thanks, just looking at the output now

#

Interesting! It shows the full path to the library for the macos build, but not the ios build. Let me turn off the macos build....

#

Yes, it is in there but I cant paste the output because its too long.

#
% zig build --verbose
/Volumes/user/zig/zig-macos-aarch64-0.14.0/zig translate-c --listen=- -target aarch64-ios -I /Users/user/.cache/zig/p/sdl-0.2.0+3.2.8-7uIn9FxHfQE325TK7b0qpgt10G3x1xl-3ZMOfTzxUg3C/include -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/System/Library/Frameworks /Users/user/.cache/zig/p/sdl-0.2.0+3.2.8-7uIn9FxHfQE325TK7b0qpgt10G3x1xl-3ZMOfTzxUg3C/include/SDL3/SDL.h
/Volumes/user/zig/zig-macos-aarch64-0.14.0/zig translate-c --listen=- -target aarch64-ios -I /Volumes/user/zig/cc/libs/stb -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/System/Library/Frameworks /Volumes/user/zig/cc/libs/stb/stb_impl.c
/Volumes/user/zig/zig-macos-aarch64-0.14.0/zig build-lib /Volumes/user/zig/cc/libs/SDL3.xcframework/ios-arm64/SDL3.framework/SDL3.a /Volumes/user/zig/cc/libs/SDL3.xcframework/ios-arm64/SDL3.framework/SDL3.a -ODebug -target aarch64-ios -mcpu baseline -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/System/Library/Frameworks -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/lib --dep stb --dep sdl -Mroot=/Volumes/user/zig/cc/src/main.zig -ODebug -target aarch64-ios -mcpu baseline -Mstb=/Volumes/user/zig/cc/.zig-cache/o/103745448efae2952fcf51cd3f880fc1/stb_impl.zig -ODebug -target aarch64-ios -mcpu baseline -Msdl=/Volumes/user/zig/cc/.zig-cache/o/5337ab3d14a8332254dae9c375e4c9eb/SDL.zig --verbose-link --cache-dir 
#
/Volumes/user/zig/cc/.zig-cache --global-cache-dir /Users/user/.cache/zig --name cc-ios -static --zig-lib-dir /Volumes/user/zig/zig-macos-aarch64-0.14.0/lib/ --listen=-
user@users-MacBook-Pro cc % nm ios/cc/libcc-ios.a | grep _SDL_Init
                 U _SDL_Init
#

So is it correct oassume that mylib.addObjectFile() should link one object file to the one that is being built?

#

The last comment in that ticket is "so is static linking just not supported atm?"

molten birch
#

I think I worked out what is going on, but I am not sure if this was the cause. SDL3 delivers mac framework pacakges with library files that are sometimes "fat" and sometimes not "fat." It seems like addObjectFile works with thin object files (ie arm64) but not fat object files (i.e. merged arm64 and x68). The solution is to use the mac lipo command to split out the fat files into thin files.