The error cannot find auto-link library XCTest and XCTestSwiftSupport?

This morning I updated my mac and then updated Xcode to 11.4.
And then I opened my project (changed nothing, but built successfully yesterday).
It shows the error "Could not find or use auto-linked library 'XCTestSwiftSupport' ld: warning: Could not find or use auto-linked framework 'XCTest'"
Do you meet the weird issue?
I found the linkerror to link static libraries

5 Likes

I have faced with the same issue none of found solutions are working.

I have the exact same issue, and I haven't found any solution so far.
I have a full swift project which is building nicely with Xcode 11.3.1

1 Like

In my case settings ENABLE_TESTING_SEARCH_PATHS to YES fixed the issue.

26 Likes

Thanks @georgescumihai; that worked! I experienced this issue after I added a custom extension to Apple's XCTestCase class in a library that I created. How did you discover this solution? Is there a reference article somewhere with more details on all of these build settings?

2 Likes

that works for me too. thx

Don't remember exactly, most likely stackoverflow.

The actual solution is to exclude test sources from main targets build. For Xcode 12.04 select target / Build Phases / Compile Sources and remove the test classes.

The test classes should be only in the test Target

8 Likes

Yey! It's done! Thanks :)

That works too! Thanks

I added ViewInspector library by SPM and selected main target instead of test target, same problem happened. Thanks to @yerlibilgin , I re-add the library and select correct target, after that i can check at Build Phases > Link Binary With Libraries for both targets.

2 Likes

Worked perfectly for me

Awesome, this is the actual fix. Thanks man!

Thank you for this! Makes so much sense now.

Hi everyone,

I landed here because I, too, experienced this today.

What happened to me was that I added the test assertions library Nimble as a Package Dependency to the project and Xcode automatically linked it against the app target.

So, the failures I saw were legit, in that the app target has no access to XCTest. Removing the library from the app target by going to "App Target Name" > Build Phases > Link Binary With Libraries solved the issue.

Cheers.

2 Likes

yes it works for me.
I can not import the same library to both main target and test target.