0

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 <[email protected]>"
    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?

7
  • I'm not familiar with Conan, but you could install prebuilt libxml2 from quasi-msys2. I can post complete instructions if needed. Commented Mar 13, 2023 at 7:00
  • It seems you are using the legacy CMake integration, which will not work with the new cross-build model. I'd try updating the recipe to use from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout. A conan new hello/0.1 -m=cmake_lib will give you a working example. Commented Mar 13, 2023 at 9:31
  • @drodri I don't see how that's relevant to building dependencies. I've switched as you said, but no change in the result. libxml2 still can't find its own headers. Commented Mar 13, 2023 at 10:46
  • It is very related. The libxml2 recipe has been modernized to be 2.0 ready (github.com/conan-io/conan-center-index/discussions/16196), that means that it is using the modern integrations, which use other mechanisms for configuration like [conf] (see conan config list) and [buildenv] instead of [env] Commented Mar 14, 2023 at 21:41
  • I switched to 2.0 and it still fails with the same error. zstd and zlib don't though. Not sure if it's an issue just with libxml or autotools packages generally Commented Mar 15, 2023 at 0:53

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

This worked around the config.h issue. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.