I try to use this new language to start a new project with Some of my old code, I used Libxml2.2 in my old project,so xcode shows "libxml.h/parse.h file not found" after my putting the code in my new project. i have already imported the "libxml2.2.dylib"
-
This is good read https://spin.atomicobject.com/2015/02/23/c-libraries-swift/ – onmyway133 May 07 '16 at 19:27
4 Answers
I 've made it work with CommonCrypto https://github.com/onmyway133/CommonCrypto.swift but libxml should be the same. Things to keep in mind
module.modulemap
Read http://clang.llvm.org/docs/Modules.html#module-map-language
Create a folder named libxml2
(in my case, it is at the same directory as my project file), then create a module.modulemap
file inside
module libxml2 {
header "/usr/include/libxml2/libxml/tree.h"
export *
}
Here I add just tree.h
, but you can add more for your need
SWIFT_INCLUDE_PATHS
Go to Target Build Settings, add this into Import Paths
${SRCROOT}/libxml2
HEADER_SEARCH_PATHS
Read Why am I getting this "libxml/tree.h file not found" error?
Go to Target Build Settings, add this into Header Search Paths
$(SDKROOT)/usr/include/libxml2
Interesting related posts

- 1
- 1

- 45,645
- 31
- 257
- 263
To get this working with my project in Xcode 6, I navigated to "Build Settings" for my project, and selected my target. I then searched for "Header Search Paths" in the Build Settings, and added the following line to both debug and release:
$(SDKROOT)/usr/include/libxml2

- 1,035
- 9
- 23
-
This is not working, as the compiler will says that you can't include non-modular include – Loegic Jul 28 '15 at 09:26
-
There is currently a modulemap file for libxml2; perhaps it didn't exist when this question/comment were written. Note that that file actually suggests that you "Add "-Xcc -I$(SDKROOT)/usr/include/libxml2" to OTHER_SWIFT_FLAGS in Xcode project" as of Xcode 9. – Ben Pious Aug 29 '18 at 23:52
I found that you can leave out importing 'libxml2.2.dylib' if you add '-lxml2' to OTHER_LDFLAGS.

- 353
- 4
- 6
You will have to create a custom module map
file containing the header of libxml/tree.h
like so :
module libxml [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
export *
}
Then you place this file (module.modulemap) inside a folder -module for example- and add it to your project's and target's build settings
.
You can now use @import libxml;
in your code.

- 3,390
- 20
- 33