Xcode 9.3中Swift项目集成libxml报错:无法构建Objective-C模块‘libxml’
Hey there, I’ve run into this exact issue before after upgrading to Xcode 9.3—here’s how to fix it properly:
The Root Cause
Xcode 9.3 updated the iOS SDK to include an official module map for libxml2, which conflicts with the custom module.modulemap you created earlier. This clash is why you’re seeing the "Could not build Objective-C module 'libxml'" error and issues with the _xmlEnumeration struct definition.
Step-by-Step Fix
Delete your custom
module.modulemapfile
Get rid of the file you created with this content:module libxml [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h" export * }It’s no longer needed and is causing the conflict.
Update your project’s Header Search Paths
Go to your project’s Build Settings, search for Header Search Paths, and add this path:$(SDKROOT)/usr/include/libxml2Make sure the path is set to Recursive (check the box next to it) to ensure all nested headers are found correctly.
Import the official module in your Swift code
Replace your oldimport libxmlwith:import libxml2This uses the official SDK module that Xcode 9.3 now provides natively, which includes all necessary headers and avoids symbol conflicts.
That’s it—your project should build without those errors now. The official module handles all the header references properly, so you don’t need to manage a custom module map anymore.
内容的提问来源于stack exchange,提问作者AppleBee

