Skip to content

[scripts] Set default PKG_CONFIG_PATH to help cross-compilation on Linux#51242

Closed
vserdyuk wants to merge 2 commits intomicrosoft:masterfrom
vserdyuk:qt-cross-compilation
Closed

[scripts] Set default PKG_CONFIG_PATH to help cross-compilation on Linux#51242
vserdyuk wants to merge 2 commits intomicrosoft:masterfrom
vserdyuk:qt-cross-compilation

Conversation

@vserdyuk
Copy link
Copy Markdown
Contributor

@vserdyuk vserdyuk commented Apr 18, 2026

This fixes qtbase:arm64-linux on x64-linux host. Tested on Ubuntu 24.04.

Based on https://wiki.qt.io/Cross-Compile_Qt_6_for_Raspberry_Pi

@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 18, 2026

This fixes qtbase:arm64-linux on x64-linux host. Tested on Ubuntu 24.04.

No, it makes things worse: It adds host (x64) directories which are incompatible with target (arm64) binaries.

What vcpkg would need is using a pkgconfig tool pre-configured for the target prefix/sysroot when building for the target (but not when building for the host!). It is probably possible to inject this via the triplet file. Some environment would provide a <autotools-target-triplet>-pkg-config wrapper script.

@vserdyuk
Copy link
Copy Markdown
Contributor Author

No, it makes things worse: It adds host (x64) directories which are incompatible with target (arm64) binaries.

How is that? It adds /usr/lib/pkgconfig/ and /usr/lib/aarch64-linux-gnu/pkgconfig/ (installed on the x64 host with e.g. apt install libxkbcommon-dev:arm64). It does not add /usr/lib/x86_64-linux-gnu/pkgconfig/.

The Qt binaries built with vcpkg are then used to cross-compile my project and it runs fine on target arm64 Ubuntu 24.04.

Though maybe I'm missing some other cases for which this patch would actually make things worse.

@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 18, 2026

This is from /usr/lib/pkgconfig, but not arm64:

$ cat /usr/lib/pkgconfig/opencl-12.9.pc 
cudaroot=/usr/local/cuda-12.9
libdir=${cudaroot}/targets/x86_64-linux/lib
includedir=${cudaroot}/targets/x86_64-linux/include

Name: opencl
Description: CUDA OpenCL Library
Version: 12.9
Libs: -L${libdir} -lopencl
Cflags: -I${includedir}

(I do believe that it works for your Qt binaries. But IMO the suggested implementation is too specific for a particular case.)

@vserdyuk vserdyuk force-pushed the qt-cross-compilation branch from df426d0 to 27ee2ea Compare April 19, 2026 03:18
@vserdyuk
Copy link
Copy Markdown
Contributor Author

Now I see. On my system /usr/lib/pkgconfig was just empty. So I think we can just remove that.

@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 19, 2026

/usr/share/pkgconfig isn't much safer. While those files should not directly reference platform-specific artifacts (-l, -L), they still expose dependencies (Requires:) which may break resolving modules.

IMO the customization point is the triplet file (via "overlay triplets"). But things get interesting when you want the same in a top-level project and in manifest-mode dependencies.

Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dg0yt that makes it too easy to accidentally depend on host bits.

@BillyONeal BillyONeal marked this pull request as draft April 20, 2026 23:38
@vserdyuk vserdyuk changed the title [scripts] Set default PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR to help c… [scripts] Set default PKG_CONFIG_PATH to help cross-compilation on Linux Apr 21, 2026
@vserdyuk
Copy link
Copy Markdown
Contributor Author

Looks like setting only PKG_CONFIG_PATH is enough.

CI building qtbase failed last time probably because of missing arm64 system packages. The following works for me:

sudo apt install bison flex libtool autoconf automake autoconf-archive python3-distutils python3-jinja2 '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev libegl1-mesa-dev libsm-dev

sudo apt install '^libxcb.*-dev':arm64 libx11-xcb-dev:arm64 libglu1-mesa-dev:arm64 libxrender-dev:arm64 libxi-dev:arm64 libxkbcommon-dev:arm64 libxkbcommon-x11-dev:arm64 libegl1-mesa-dev:arm64 libxrandr-dev:arm64 libsm-dev:arm64 python3-venv

@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 21, 2026

... and it only reaches ports which use the CMake toolchain (CMake project mode).

@BillyONeal
Copy link
Copy Markdown
Member

After discussion with @vicroms we have decided to close this.

@BillyONeal BillyONeal closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants