gtk-rs / glib

DEPRECATED, use https://github.com/gtk-rs/gtk-rs-core repository instead!
http://gtk-rs.org/
MIT License
93 stars 62 forks source link

Cannot build on windows #712

Closed doivosevic closed 4 years ago

doivosevic commented 4 years ago

Hi everyone, I'm trying to follow https://www.reddit.com/r/rust/comments/86kmhu/compiling_rust_windows_gtk_stepbystep/ and I cannot do a cargo build.

cargo build --target=x86_64-pc-windows-gnu
   Compiling webpki v0.21.3
   Compiling sct v0.6.0
   Compiling glib-sys v0.10.1
error: failed to run custom build command for `glib-sys v0.10.1`

Caused by:
  process didn't exit successfully: `\target\debug\build\glib-sys-fe281ceb0a84f9fc\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-env-changed=GLIB_2.0_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-pc-windows-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_pc_windows_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS

  --- stderr
  pkg-config has not been configured to support cross-compilation.

                  Install a sysroot for the target platform and configure it via
                  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
                  cross-compiling wrapper for pkg-config and set it via
                  PKG_CONFIG environment variable.
warning: build failed, waiting for other jobs to finish...
error: build failed

Can anyone help me? I have 0 knowledge about cross compiling or anything related. I'm on Windows 10 Home, using msys2 to get some dependencies and on latest Rust.

sdroege commented 4 years ago

What does pkg-config --libs glib-2.0 output?

doivosevic commented 4 years ago

Good point. It does say No package 'glib-2.0' found I did use msys2 to install glib so I can see all these glib files and folders in msys2 and I have

image in my path. Which file exactly should be visible in the path? Maybe I'm missing something

image

sdroege commented 4 years ago

The glib-2.0.pc needs to be in PKG_CONFIG_PATH but that might not be enough. The pkg-config from MSYS2 is notoriously broken: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/#installation-windows

doivosevic commented 4 years ago

Thank you so much! So for the noobs like me you do in CMD (not poweshell, there there's a different syntax to set env variables):

set PKG_CONFIG_ALLOW_CROSS=1
set PKG_CONFIG_PATH=C:\msys64\mingw64\lib\pkgconfig\
cargo build --target=x86_64-pc-windows-gnu

and that should be it I think

sdroege commented 4 years ago

set PKG_CONFIG_ALLOW_CROSS=1

Unclear why this is required, unless your pkg-config is for 32 bit Windows.

doivosevic commented 4 years ago

Yeah so I rechecked a few times to make sure, I don't remember exactly how I got pkg-config in my msys2 but it seems I really need the =1 as well. I guess some default install somewhere gets you the 32 bit one

nirbheek commented 4 years ago

What pkg-config have you installed? There are separate ones for mingw32, mingw64, and msys and two implementations: pkgconf and pkg-config (I stripped the python and ruby bindings from the results):

$ pacman -Ss pkg-config
mingw32/mingw-w64-i686-pkg-config 0.29.2-1 (mingw-w64-i686-toolchain)
    A system for managing library compile/link flags (mingw-w64)
mingw32/mingw-w64-i686-pkgconf 1.3.8-1
    pkg-config compatible utility which does not depend on glib
mingw64/mingw-w64-x86_64-pkg-config 0.29.2-1 (mingw-w64-x86_64-toolchain) [installed]
    A system for managing library compile/link flags (mingw-w64)
mingw64/mingw-w64-x86_64-pkgconf 1.3.8-1
    pkg-config compatible utility which does not depend on glib
msys/pkg-config 0.29.2-1 (base-devel) [installed]
    A system for managing library compile/link flags
msys/pkgconf 0.9.11-1
    pkg-config compatible utility which does not depend on glib

You can check by doing type -a pkg-config:

$ type -a pkg-config
pkg-config is /mingw64/bin/pkg-config
pkg-config is /usr/bin/pkg-config
pkg-config is /bin/pkg-config

In your case, you'd need mingw64/mingw-w64-x86_64-pkg-config.