stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.73k stars 1.57k forks source link

build errors when statically linking for release #896

Closed paultopia closed 3 years ago

paultopia commented 5 years ago

Hi there,

I'm getting a build error when building for release using SPM for a pure CLI app in Swift 5 or 4.2 (OSX 10.14.4, XCode 10.2, but not using xcode at all/no xcodeproj created etc.). I'm using the most recent version of SQLite.swift referenced in the readme, i.e., my Package.swift contains package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.11.5"), and the build command I'm using is swift build -c release -Xswiftc -static-stdlib

Note that the problem arises only when building for release. A debug build (bare swift build from the CLI`) generates no errors and everything appears to be running just fine. So something seems to have gone awry between, I guess, SQLib.swift and the static linking process for the stdlib.

Following an earlier issue #592 , I also tried passing a flag to link sqlite3

swift build -c release -Xswiftc -static-stdlib -Xlinker -lsqlite3

but no dice.

I also see #828 with a similar recent error, but I'm not building with xcode, but with SPM, so not sure how to change that c module setting referenced in that issue.

The build error is MASSIVE, like, spews out so much error garbage that it floods my terminal history, but the last few lines are:

  "_swift_unknownObjectRetain", referenced from:
      _$sSayxSicir in RTree.swift.o
      _$ss10ArraySliceV017_copyToContiguousA0s0eA0VyxGyFs5UInt8V_Tg5Tf4g_n in xxHash64.swift.o
  "_swift_willThrow", referenced from:
      _$s6SQLite10ConnectionC_8readonlyA2C8LocationO_SbtKcfC in Connection.swift.o
      _$s6SQLite10ConnectionC_8readonlyACSS_SbtKcfC in Connection.swift.o
      _$s6SQLite10ConnectionC7executeyySSKF in Connection.swift.o
      _$s6SQLite10ConnectionC7executeyySSKFs5Int32VyKXEfU_ in Connection.swift.o
      _$s6SQLite10ConnectionC7prepareyAA9StatementCSS_AA7Binding_pSgdtKF in Connection.swift.o
      _$s6SQLite10ConnectionC7prepareyAA9StatementCSS_SDySSAA7Binding_pSgGtKF in Connection.swift.o
      _$s6SQLite10ConnectionC3runyAA9StatementCSS_AA7Binding_pSgdtKF in Connection.swift.o
      ...
ld: symbol(s) not found for architecture x86_64

I believe this is SQLite code, as a bit up in the gigantic build error spew I see a bunch of references to database and specifically to SQLite code, e.g.:

  "_swift_makeBoxUnique", referenced from:
      ___swift_mutable_project_boxed_opaque_existential_1 in Query.swift.o
  "_swift_once", referenced from:
      _$s6SQLite10ConnectionC7executeyySSKF in Connection.swift.o
      _$s6SQLite10ConnectionC7executeyySSKFs5Int32VyKXEfU_ in Connection.swift.o
      _$s6SQLite10ConnectionC14createFunction_13argumentCount13deterministic_ySS_SuSgSbAA7Binding_pSgSayAIGctFys13OpaquePointerVSg_s5Int32VSpyAMGSgtcfU0_ in Connection.swift.o
      _$s6SQLite10ConnectionC15createCollationyySS_So18NSComparisonResultVSS_SStctKF in Connection.swift.o
      _$s6SQLite10ConnectionC_8readonlyA2C8LocationO_SbtKcfcTf4gnn_n in Connection.swift.o
      _$s6SQLite10ConnectionC11transaction33_79F5A2E9E6411E14122CA7C8A9C356C7LL___2orySS_yyKXES2StKFTf4xnxxn_n in Connection.swift.o
      _$s6SQLite9StatementC4bind33_BBABA35034D0672F50B2547BC77385B8LL_7atIndexyAA7Binding_pSg_SitF in Statement.swift.o
      ...
  "_swift_release", referenced from:
      _$s11ChangesCore8DatabaseVACycfcy6SQLite12TableBuilderCXEfU_ in db.swift.o
      _$s11ChangesCore8DatabaseV6upsertys5Int64VSgAA10AttributesVF in db.swift.o
      _$s11ChangesCore8DatabaseV5fetchyAA10AttributesVSgSSF in db.swift.o
      _$s11ChangesCore8DatabaseVACycfCTf4d_n in db.swift.o
      ___swift_destroy_boxed_opaque_existential_1 in db.swift.o
      _$s11ChangesCore8DatabaseVwxx in db.swift.o
      _$s11ChangesCore8DatabaseVwca in db.swift.o
      ...
  "_swift_release_n", referenced from:
      _$s11ChangesCore8DatabaseV5fetchyAA10AttributesVSgSSF in db.swift.o
      _$s6SQLite10ConnectionC7executeyySSKF in Connection.swift.o
      _$s6SQLite10ConnectionC11transaction33_79F5A2E9E6411E14122CA7C8A9C356C7LL___2orySS_yyKXES2StKFyyKXEfU_Tf4nxnxx_n in Connection.swift.o
      _$s6SQLite0A7Decoder33_AC67620244ED67AEDED85ABF4E1A1948LLC0A22KeyedDecodingContainerC6decode_6forKeyS2bm_xtKF in Coding.swift.o
      _$s6SQLite0A7Decoder33_AC67620244ED67AEDED85ABF4E1A1948LLC0A22KeyedDecodingContainerC6decode_6forKeyS2im_xtKF in Coding.swift.o
      _$s6SQLite0A7Decoder33_AC67620244ED67AEDED85ABF4E1A1948LLC0A22KeyedDecodingContainerC6decode_6forKeyS2fm_xtKF in Coding.swift.o
      _$s6SQLite0A7Decoder33_AC67620244ED67AEDED85ABF4E1A1948LLC0A22KeyedDecodingContainerC6decode_6forKeyS2dm_xtKF in Coding.swift.o
      ...
  "_swift_retain", referenced from:
      _$s11ChangesCore10AttributesVwCP in attributes.swift.o
      _$s11ChangesCore8DatabaseVACycfcy6SQLite12TableBuilderCXEfU_ in db.swift.o
      _$s11ChangesCore8DatabaseV6upsertys5Int64VSgAA10AttributesVF in db.swift.o
      _$s11ChangesCore8DatabaseV5fetchyAA10AttributesVSgSSF in db.swift.o
      _$s11ChangesCore8DatabaseVACycfCTf4d_n in db.swift.o
      _$s11ChangesCore8DatabaseVwCP in db.swift.o
      _$s11ChangesCore8DatabaseVwcp in db.swift.o

For reference, the failing build in swift 5 is at this commit in this project.

JohnGoodstadt commented 5 years ago

I am also having this problem. I can run debug fine. I can archive and push to testflight. When testflight version comes to a phone it crashes on opening. This is the error:

dyld: Symbol not found: _OBJCCLASS$__TtCs12_SwiftObject Referenced from: /private/var/containers/Bundle/Application/7EDE0D24-FB85-4557-BC6D-0A4780451C9A/memorizeMusic.app/Frameworks/SQLite.framework/SQLite Expected in: /usr/lib/swift/libswiftCore.dylib in /private/var/containers/Bundle/Application/7EDE0D24-FB85-4557-BC6D-0A4780451C9A/memorizeMusic.app/Frameworks/SQLite.framework/SQLite

Hope this helps to fix - as I am rather stuck. Note this is only on an IOS 12.2 device.

I should add that, today, I solved my problem by downloading the previous XCode 10.1 and archiving/uploading to testflight. It now runs on an IOS12.2 device.

Thanks John Goodstadt

mackoj commented 5 years ago

Just use swift build -c release