1

Is there a way to build a dynamic library (dylib) from go code? I get it done for x86_64 and i386, but for arm64 and armv7(s) it says "buildmode=c-shared is not supported on darwin/arm". Why? Or is there a way to convert a static a-library file into a dynamically linked Mach-O dylib? I can merge the dylibs and a-files into one universal binary using lipo, but that still leaves them as static archives.

I'm sure there must be a command to convert a static archive into a dynamic Mach-O library. Any help appreciated, thank you!

kometen
  • 6,536
  • 6
  • 41
  • 51
TopperDEL
  • 73
  • 2
  • 10
  • Does this answer your question? [Convert .a to .dylib in Mac osx](https://stackoverflow.com/questions/25321911/convert-a-to-dylib-in-mac-osx) – Siguza May 26 '20 at 13:43
  • Same concept applies to iOS, just use `xcrun -sdk iphoneos clang -arch arm64 [rest of flags]`. – Siguza May 26 '20 at 13:44
  • That is a good starting ooint, Thank you @Siguza - but I get error with missing Symbols like this: Undefined symbols for architecture arm64: "_CFBundleCopyResourceURL", referenced from: _init_working_dir in storj_uplink.a(000021.o) "_CFBundleGetMainBundle", referenced from: _init_working_dir in storj_uplink.a(000021.o) – TopperDEL May 26 '20 at 18:49
  • Ah, got it! Had to add -Framework CoreFoundation. Thank you @Siguza! – TopperDEL May 26 '20 at 19:03
  • When I follow these instructions to compile the Storj uplink-c SDK, I got a runtime error: libuplinkc.dylib`golang.org/x/sys/cpu.getisar0: -> 0x104d7b110 <+0>: mrs x0, ID_AA64ISAR0_EL1 0x104d7b114 <+4>: str x0, [sp, #0x8] 0x104d7b118 <+8>: ret 0x104d7b11c <+12>: udf #0x0 Did anyone encounter this? Described in more detail on https://github.com/storj-thirdparty/uplink-swift/issues/5 – regularlearner Nov 12 '21 at 07:14

1 Answers1

1

@Siguza gave me the correct hint. This is the final way to convert my static archive to a dynamic library for iOs - at least for arm64. I tried the same for armv7, but that lead to other issues and I decided to leave 32bit out here.

xcrun -sdk iphoneos clang -arch armv7 -fpic -shared -Wl,-all_load libmystatic.a -framework Corefoundation -o libmydynamic.dylib
TopperDEL
  • 73
  • 2
  • 10