Compiling swift fails because 'unicode/ucnv.h' is not found

I have some problems to compile swift on macOS. I followed the instructions on The tools (cmake, ninja) are installed from MacPorts.

$ ./swift/utils/build-script --release-debuginfo --debug-swift-stdlib

ultimately fails with

+ /opt/local/bin/cmake --build /Users/martin/swift-source/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/llvm-macosx-x86_64 -- -j4 all
[124/1944][  6%][26.234s] Building CXX...nifest.dir/WindowsManifestMerger.cpp.o
FAILED: lib/WindowsManifest/CMakeFiles/LLVMWindowsManifest.dir/WindowsManifestMerger.cpp.o 
/Applications/  -DGTEST_HAS_RTTI=0 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/WindowsManifest -I/Users/martin/swift-source/llvm/lib/WindowsManifest -I/opt/local/include/libxml2 -Iinclude -I/Users/martin/swift-source/llvm/include -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -g -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -O2  -isysroot /Applications/ -mmacosx-version-min=10.9   -UNDEBUG  -fno-exceptions -fno-rtti -MD -MT lib/WindowsManifest/CMakeFiles/LLVMWindowsManifest.dir/WindowsManifestMerger.cpp.o -MF lib/WindowsManifest/CMakeFiles/LLVMWindowsManifest.dir/WindowsManifestMerger.cpp.o.d -o lib/WindowsManifest/CMakeFiles/LLVMWindowsManifest.dir/WindowsManifestMerger.cpp.o -c /Users/martin/swift-source/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
In file included from /Users/martin/swift-source/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp:21:
In file included from /opt/local/include/libxml2/libxml/xmlreader.h:14:
In file included from /opt/local/include/libxml2/libxml/tree.h:1307:
In file included from /opt/local/include/libxml2/libxml/xmlmemory.h:218:
In file included from /opt/local/include/libxml2/libxml/threads.h:35:
In file included from /opt/local/include/libxml2/libxml/globals.h:18:
In file included from /opt/local/include/libxml2/libxml/parser.h:810:
/opt/local/include/libxml2/libxml/encoding.h:31:10: fatal error: 'unicode/ucnv.h' file not found
#include <unicode/ucnv.h>

(I can provide the full transcript, if necessary.) The same compiler error was reported at, so this seems to be a MacPorts problem.

The solution (if I understand it correctly from that thread) is to add the include path -I/opt/local/include to the compiler options. Unfortunately, I am not familiar with cmake (or the Swift build tools), so any advice how that can be done would be appreciated.

Regards, Martin.

PS: I wasn't sure under which category this should be posted, please move it to a different one if appropriate.

1 Like

I had this issue in a non-Swift project (the llvm-bolt tool), and was able to fix it by adding this line


To the very beginning of my CMakeLists.txt file.
I think Mac ships with a bad version of libxml2, and CMake uses it instead of the proper version installed by Homebrew/MacPorts/etc.

Thank you for your response. After updating the ports to the latest version I could not reproduce the problem anymore, so apparently that has been fixed by MacPorts in the meantime.

Terms of Service

Privacy Policy

Cookie Policy