mattgallagher / CwlPreconditionTesting

A Mach exception handler that allows Swift precondition failures to be caught and tested.
ISC License
175 stars 46 forks source link

Undefined symbols for architecture x86_64: "_catchExceptionOfKind" #16

Closed skyylex closed 4 years ago

skyylex commented 5 years ago

Hi,

From time to time I'm facing the following issue when building the Tests target that uses catchBadInstruction { } from CwlPreconditionTesting.

import XCTest
import CwlPreconditionTesting
import CarPlay

final class Tests: XCTestCase {
    func testFiresFatalError {
        let catchedFatalError = catchBadInstruction { }

        XCTAssertNotNil(catchedFatalError)
    }
}

Xcode build log:

Undefined symbols for architecture x86_64:
  "_catchExceptionOfKind", referenced from:
      CwlCatchException.(catchReturnTypeConverter in _841BEC3F94220F0DFD4EA4E9DDB3DC93)<A where A: __C.NSException>(_: A.Type, block: () -> ()) -> A? in libCwlCatchException.a(CwlCatchException-b635c7ceaebf0fe95fbf8ddcf7fc6874546dd0ad373c125772be5cdf73ff33d0.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Environment:

Used versions:

caipre commented 4 years ago

For anyone blocked by this, the recent 2.0 release seems to've fixed the issue for me. I was pulling in this library via Quick and Nimble, which haven't updated to 2.0 yet (even after six whole hours! 😛 ), so I just added this library directly:

image

Hats off to the developers!

mattgallagher commented 4 years ago

Yes, if you're using Quick/Nimble, pull the master branch since the update to fix this problem (update CwlPreconditionTesting 2.0.0-beta.1 or newer) is on master but is not part of the latest (8.0.4) release.

FYI, I believe this issue is due to an Xcode bug around the SWIFT_PACKAGE macro (although it's not totally clear since there's been no response on the Feedback). In any case, CwlCatchException 2.0.0-beta.1 and greater (incl. 2.0.0) works around the issue by removing the macro entirely:

https://github.com/mattgallagher/CwlCatchException/commit/b1b53c1d6eedf39555745fa7f6a70c99177883ba

tl;dr pull CwlPreconditionTesting 2.0.0-beta.1 or newer (incl. 2.0.0) you'll get the fix.