I've been trying to cross-compile an application from Linux > Windows which depends on libxml2. I'm trying to use Conan for managing the dependencies.
I've been running into various roadblocks, the current issue being that libxml2 can't seem to find its own headers.
First, it couldn't find the generated config.h header:
x86_64-w64-mingw32-gcc -m64 -O3 -DNDEBUG -I/home/robert/.conan/data/libiconv/1.17/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/include -I/home/robert/.conan/data/zlib/1.2.13/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/include -DWIN32 -m64 -L/home/robert/.conan/data/libiconv/1.17/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/lib -L/home/robert/.conan/data/zlib/1.2.13/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/lib /home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/xmllint.c -o xmllint
In file included from /home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/xmllint.c:9:
/home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/libxml.h:30:10: fatal error: config.h: No such file or directory
30 | #include "config.h"
| ^~~~~~~~~~
compilation terminated.
I tried manually copying it into the source folder, but that only caused it fail on another header:
x86_64-w64-mingw32-gcc -m64 -O3 -DNDEBUG -I/home/robert/.conan/data/libiconv/1.17/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/include -I/home/robert/.conan/data/zlib/1.2.13/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/include -DWIN32 -m64 -L/home/robert/.conan/data/libiconv/1.17/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/lib -L/home/robert/.conan/data/zlib/1.2.13/_/_/package/c6817f477abe7e9a917b102f37dc1fd0c2d95f50/lib /home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/xmllint.c -o xmllint
In file included from /home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/xmllint.c:9:
/home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/src/libxml.h:31:10: fatal error: libxml/xmlversion.h: No such file or directory
31 | #include <libxml/xmlversion.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: xmllint] Error 1
libxml2/2.10.3:
libxml2/2.10.3: ERROR: Package '6a818f7d8bbba2942e1499f2d61557299d4122bd' build failed
libxml2/2.10.3: WARN: Build folder /home/robert/.conan/data/libxml2/2.10.3/_/_/build/6a818f7d8bbba2942e1499f2d61557299d4122bd/build-release
ERROR: libxml2/2.10.3: Error in build() method, line 298
autotools.make(target)
ConanException: Error 2 while executing make xmllint -j4
Here's my conanfile:
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
class SfeMapconvConan(ConanFile):
name = "sfe-mapconv"
version = "0.1.0"
license = "MIT License"
author = "Robert The Sable <robertthesable@gmail.com>"
url = "https://gitlab.com/robertsstuff/sfc-mapconv"
description = "TMX map converter for the Super Famicom Fire Emblem games."
settings = "os", "compiler", "build_type", "arch"
requires = "zlib/1.2.13", "libxml2/2.10.3", "zstd/1.5.4"
options = {"mode": ["tests", "qt"]}
generators = "cmake"
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
My profile is based on one of the guides in Conan's documentation:
toolchain=/usr/x86_64-w64-mingw32 # Adjust this path
target_host=x86_64-w64-mingw32
cc_compiler=gcc
cxx_compiler=g++
[env]
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
STRIP=$target_host-strip
RC=$target_host-windres
[settings]
# We are cross-building to Windows
os=Windows
arch=x86_64
compiler=gcc
os_build=Linux
arch_build=x86_64
build_type=Release
# Adjust to the gcc version of your MinGW package
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Release
And I'm trying to install dependencies with:
conan install -pr:h mingw.profile -s:b os_build=Linux -o mode=qt --build=missing .
I'm using Conan 1.59.0. I tried using Conan 2, but I couldn't find any useful documentation about cross compiling from Linux > Windows with Conan 2. The mingw version is 10.3.0-14 from apt.
Can anyone see what I'm doing wrong?
If you only need the libxml2 library, you can try and disable the utils build (utils like xmllint)
class SfeMapconvConan(ConanFile):
def configure(self):
self.options['libxml2'].include_utils=False