Swift 4.0 报错No such module 'libxmlKanna',手动装Kanna未解决求帮助
Hey there, I’ve wrestled with this exact error back when working with Swift 4.0 and Kanna—let’s break down actionable fixes that should get you up and running:
Confirm you’re using a Swift 4.0-compatible Kanna version
Not all Kanna releases work with Swift 4.0. Grab the source code from the repo’s Swift 4.x tagged releases (look for versions explicitly noted to support Swift 4.0). When adding files to your project, make sure you include:- All files in the
Sources/Kannafolder - The entire
Sources/libxml2folder, including the criticalmodule.modulemapfile—missing this is the #1 cause of "module not found" errors here.
- All files in the
Tweak your target’s build settings
Head to your project target → Build Settings and adjust these key settings:- Header Search Paths: Add the relative path to your
libxml2folder (e.g.,$(SRCROOT)/Kanna/Sources/libxml2) and set it to recursive. - Other Linker Flags: Add
-lxml2to ensure the linker connects to the libxml2 library. - Enable Modules (C and Objective-C): Ensure this is set to Yes under the Apple Clang - Language section.
- Header Search Paths: Add the relative path to your
Clean Xcode’s cache and rebuild
Xcode’s cached data often causes weird module issues. Follow these steps in order:- Go to
Product → Clean Build Folder(hold the Option key to reveal this option if you only see "Clean") - Quit Xcode entirely
- Delete the
DerivedDatafolder (find it viaXcode → Preferences → Locations → DerivedData) - Reopen your project and build again.
- Go to
Check for naming conflicts
Make sure there are no other files, frameworks, or custom modules in your project namedKannaorlibxmlKanna—Xcode might be picking up a conflicting module instead of the one you added.Try integrating Kanna as a subproject
If manual file addition isn’t working, drag theKanna.xcodeprojfrom the downloaded source into your project’s navigator. Then:- Go to your target → General → Embedded Binaries, click the + button and select
Kanna.frameworkfrom the Kanna subproject. - Navigate to Build Phases → Link Binary With Libraries and confirm
Kanna.frameworkis listed.
- Go to your target → General → Embedded Binaries, click the + button and select
内容的提问来源于stack exchange,提问作者Steven Gardner

