Failure building x86_64-w64-mingw32 triplet of clang on Windows

I was successful building a 32-bit version clang from source on Windows using gcc-5.3. When I try to build a 64-bit version of clang on Windows with the triplet x86_64-w64-mingw32 and the 64-bit version of gcc-5.3 I get as an error:

[482/563] Linking CXX executable bin\c-index-test.exe
FAILED: bin/c-index-test.exe
cmd.exe /C "cd . && C:\utilities\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\min
gw64\bin\c++.exe -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wn
o-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -
Wdelete-non-virtual-dtor -Wno-comment -Werror=date-time -std=gnu++11 -fno-common
-Woverloaded-virtual -fno-strict-aliasing -O2 tools/clang/tools/c-index-test
/CMakeFiles/c-index-test.dir/c-index-test.c.obj tools/clang/tools/c-index-test/C
MakeFiles/c-index-test.dir/core_main.cpp.obj -o bin\c-index-test.exe -Wl,--out-
implib,lib\libc-index-test.dll.a -Wl,--major-image-version,0,--minor-image-versi
on,0 lib/libLLVMSupport.a lib/liblibclang.dll.a lib/libclangAST.a lib/libclangB
asic.a lib/libclangFrontend.a lib/libclangIndex.a C:/utilities/libxml/lib/libxml
2.lib lib/libclangFrontend.a lib/libclangDriver.a -lversion lib/libclangParse.a
lib/libLLVMMCParser.a lib/libclangSerialization.a lib/libclangSema.a lib/libclan
gEdit.a lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMOption.a lib/li
bLLVMProfileData.a lib/libclangFormat.a lib/libclangToolingCore.a lib/libclangAS
T.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.
a lib/libLLVMMC.a lib/libLLVMSupport.a -lpsapi -lshell32 -lole32 -luuid -lkernel
32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -l
advapi32 && cd ."
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3066): undefined reference to `xmlRelaxNGNewParserCtxt'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x307a): undefined reference to `xmlRelaxNGParse'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3085): undefined reference to `xmlParseDoc'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3099): undefined reference to `xmlRelaxNGNewValidCtxt'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30a7): undefined reference to `xmlRelaxNGValidateDoc'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30bb): undefined reference to `xmlGetLastError'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30d3): undefined reference to `xmlRelaxNGFreeValidCtxt'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30db): undefined reference to `xmlFreeDoc'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30e3): undefined reference to `xmlRelaxNGFree'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30eb): undefined reference to `xmlRelaxNGFreeParserCtxt'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3452): undefined reference to `xmlGetLastError'
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text.startup+0x23): undefined reference to `xmlCheckVersion'
collect2.exe: error: ld returned 1 exit status

Anyone know what I have to do to correct this problem ?

I use CMake, ninja, and mingw-64/gcc-5.3. I have not downloaded the optional 'extra' and 'compiler-rt' projects as part of LLVM on Windows.

I was successful building a 32-bit version clang from source on Windows
using gcc-5.3. When I try to build a 64-bit version of clang on Windows
with the triplet x86_64-w64-mingw32 and the 64-bit version of gcc-5.3 I get
as an error:

[482/563] Linking CXX executable bin\c-index-test.exe

FAILED: bin/c-index-test.exe
cmd.exe /C "cd . &&
C:\utilities\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\min
gw64\bin\c++.exe -Wall -W -Wno-unused-parameter -Wwrite-strings
-Wcast-qual -Wn
o-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -
Wdelete-non-virtual-dtor -Wno-comment -Werror=date-time -std=gnu++11
-fno-common
-Woverloaded-virtual -fno-strict-aliasing -O2
tools/clang/tools/c-index-test
/CMakeFiles/c-index-test.dir/c-index-test.c.obj
tools/clang/tools/c-index-test/C
MakeFiles/c-index-test.dir/core_main.cpp.obj -o bin\c-index-test.exe
-Wl,--out-
implib,lib\libc-index-test.dll.a
-Wl,--major-image-version,0,--minor-image-versi
on,0 lib/libLLVMSupport.a lib/liblibclang.dll.a lib/libclangAST.a
lib/libclangB
asic.a lib/libclangFrontend.a lib/libclangIndex.a
C:/utilities/libxml/lib/libxml
2.lib lib/libclangFrontend.a lib/libclangDriver.a -lversion
lib/libclangParse.a
lib/libLLVMMCParser.a lib/libclangSerialization.a lib/libclangSema.a
lib/libclan
gEdit.a lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMOption.a
lib/li
bLLVMProfileData.a lib/libclangFormat.a lib/libclangToolingCore.a
lib/libclangAS
T.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a
lib/libLLVMCore.
a lib/libLLVMMC.a lib/libLLVMSupport.a -lpsapi -lshell32 -lole32 -luuid
-lkernel
32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid
-lcomdlg32 -l
advapi32 && cd ."

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3066): undefined reference to
`xmlRelaxNGNewParserCtxt'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x307a): undefined reference to `xmlRelaxNGParse'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3085): undefined reference to `xmlParseDoc'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3099): undefined reference to
`xmlRelaxNGNewValidCtxt'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30a7): undefined reference to
`xmlRelaxNGValidateDoc'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30bb): undefined reference to `xmlGetLastError'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30d3): undefined reference to
`xmlRelaxNGFreeValidCtxt'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30db): undefined reference to `xmlFreeDoc'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30e3): undefined reference to `xmlRelaxNGFree'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x30eb): undefined reference to
`xmlRelaxNGFreeParserCtxt'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text+0x3452): undefined reference to `xmlGetLastError'

tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.obj:c-
index-test.c:(.text.startup+0x23): undefined reference to
`xmlCheckVersion'
collect2.exe: error: ld returned 1 exit status

Anyone know what I have to do to correct this problem ?

You are failing to link against libxml2. I don't have any idea why that
would be the case. I would recommend that you look at the cake output and
see if it failed to find the 64-bit version of libxml2 on your installation.

Why is llvm/clang looking for libxml2 ? It's not a part of the mingw-64/gcc compiler being used to build llvm/clang.

I guess you are building on msys2 with external mingw-w64.
CMake picks up msys2’s libxml2, I guess.

Could you try overriding CMake and reconfigure?

-DCMAKE_LIBRARY_PATH=“C:/mingw-w64/x86_64-4.9.3-posix-seh-rt_v4-rev1/mingw64/x86_64-w64-mingw32/lib”

I guess you are building on msys2 with external mingw-w64.

No, I am not. Ninja is calling mingw-64/gcc-5.3 directly to build llvm/clang.

CMake picks up msys2's libxml2, I guess.

I do have a 32-bit libxml2 on my Windows PATH from the GnuWin32 package. But why is a build of llvm/clang requiring libxml2, whether a 32-bit or 64-bit version ?

Could you try overriding CMake and reconfigure?
-DCMAKE_LIBRARY_PATH="C:/mingw-w64/x86_64-4.9.3-posix-seh-rt_v4-rev1/mingw64/x86_64-w64-mingw32/lib"

Why would using gcc-4.9.3 make any difference ?

I guess you are building on msys2 with external mingw-w64.

No, I am not. Ninja is calling mingw-64/gcc-5.3 directly to build
llvm/clang

.

CMake picks up msys2’s libxml2, I guess.

I do have a 32-bit libxml2 on my Windows PATH from the GnuWin32 package.
But why is a build of llvm/clang requiring libxml2, whether a 32-bit or
64-bit version ?

I don’t know why CMake finds but doesn’t ignore it.
c-index-test uses libxml2 if available. libxml2 is not essential.

We could add extra checks if libxml2 would be really available.

Could you try overriding CMake and reconfigure?
-DCMAKE_LIBRARY_PATH=“C:/mingw-w64/x86_64-4.9.3-posix-seh-rt_v4-rev1/mingw64/x86_64-w64-mingw32/lib”

Why would using gcc-4.9.3 make any difference ?

Excuse me. It was just an example. Please substitute with your mingw-w64’s path.

libxml is optional library, used if found.
Maybe CMake finds your libxml2 but does not check if its 32 or 64 bit, just assumes it’s the right one?

libxml is optional library, used if found.

Where in the llvm/clang CMake files is libxml specified ?

Maybe CMake finds your libxml2 but does not check if its 32 or 64 bit,
just assumes it's the right one?

I queried this on the CMake mailing list and am awaiting some answer from them. But I expect that if I get one it will be to ask where llvm/clang specifies libxml in its CMakeLists.txt files.

clang calls CMake find_package(libxml2) to find libxml2.
This is implemented in the CMake standard module “/usr/share/cmake-3.5/Modules/FindLibXml2.cmake”.

clang calls CMake find_package(libxml2) to find libxml2.

Where in the clang source does "find_package(libxml2)" occur ? I could not find <g> it.

You need to work on your grep skills :slight_smile:

tools/clang/CMakeLists.txt
171:find_package(LibXml2 2.5.3 QUIET)
172:if (LIBXML2_FOUND)

ismail

Thanks I found it also just searching for 'libxml2' with case being ignored in all the .txt files in clang.

Evidently CMake cannot distinguish between finding a package that corresponds to the compiler 32-bit or 64-bit build that you are doing. This surprises me as it says that if I have a 32-bit version of a package and I am doing a 64-bit build, or vice-versa, CMake will act as if it has found the package even when the package cannot work with the build. I do not see this as correct behavior for a build system.