Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 174 forks source link

Unable to build with SPM install (ld: symbol(s) not found for architecture arm64) #467

Closed kelvinharron closed 1 year ago

kelvinharron commented 1 year ago

Hi folks. We've used Cuckoo to great success in a previous project (with Cocoapods) and while spiking out a skeleton app for a new project, I've encountered a blocker in trying to set Cuckoo up with SPM.

The problem

After following the instructions for SPM -> Clean & Build, I get the following error lines.

ld: warning: Could not find or use auto-linked library 'XCTestSwiftSupport' ld: warning: Could not find or use auto-linked framework 'XCTest' Undefined symbols for architecture arm64: "_$s6XCTest7XCTFail_4file4lineySSs12StaticStringVSutF", referenced from: $s6Cuckoo11MockManagerC4failyySS7message_s12StaticStringV4file_Su4linet14sourceLocationt_tcvpZfiySSAE_AgH_SuAItAJttcfU in Cuckoo.o "swift_FORCELOAD$_XCTestSwiftSupport", referenced from: swift_FORCELOAD$XCTestSwiftSupport$_Cuckoo in Cuckoo.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Where the three failures are down to this

Screenshot 2023-05-31 at 10 27 38

Steps to reproduce

To rule out our project being the cause, I was able to reproduce it entirely with a brand-new iOS project.

Run Script ``` if [ $ACTION == "indexbuild" ]; then echo "Not running Cuckoo generator during indexing." exit 0 fi # Skip for preview builds if [ "${ENABLE_PREVIEWS}" = "YES" ]; then echo "Not running Cuckoo generator during preview builds." exit 0 fi # Define output file. Change "${PROJECT_DIR}/${PROJECT_NAME}Tests" to your test's root source folder, if it's not the default name. OUTPUT_FILE="${PROJECT_DIR}/${PROJECT_NAME}Tests/GeneratedMocks.swift" echo "Generated Mocks File = ${OUTPUT_FILE}" # Define input directory. Change "${PROJECT_DIR}/${PROJECT_NAME}" to your project's root source folder, if it's not the default name. INPUT_DIR="${PROJECT_DIR}/${PROJECT_NAME}" echo "Mocks Input Directory = ${INPUT_DIR}" # Generate mock files, include as many input files as you'd like to create mocks for. "${PROJECT_DIR}/run" --download generate --testable "${PROJECT_NAME}" \ --output "${OUTPUT_FILE}" \ "${INPUT_DIR}/ViewModel.swift" # ... and so forth, the last line should never end with a backslash # After running once, locate `GeneratedMocks.swift` and drag it into your Xcode test target group. ```

Please let me know what I can do to get it working. Thanks!

kelvinharron commented 1 year ago

SPM noob confirmed! 😆

The problem was when adding Cuckoo via SPM, I was adding it to the app project and not the tests explicitly. Resolved now!

Screenshot 2023-05-31 at 10 58 36

I'm happy to create a PR to update the README to be explicit about this if that helps!

MatyasKriz commented 1 year ago

Hey @kelvinharron, a PR that would help make this clear for others in the README would definitely be appreciated if you're willing. 🙂 And good job on finding that out yourself!

0x7067 commented 1 year ago

I'm having the same issue, even if I'm adding it to the test target

kelvinharron commented 1 year ago

@0x7067 if you create a new project and try to add cuckoo are you able to reproduce it? or is this when you try to add it to an existing projecT?

0x7067 commented 1 year ago

I'm having this issue adding Cuckoo to an existing project

0x7067 commented 1 year ago

Found out what was the issue: I had the GeneratedMocks.swift file added to the app project's target and not the test target

kelvinharron commented 1 year ago

Nice one, @0x7067 ! I think that would make a nice explicit addition to the project README! 😄

0x7067 commented 1 year ago

I agree! Will open a PR later with an edited README