2

Hello I am trying to cross compile systemd for arm, but I got stuck on 'mount' cross depencency.

I managed to cross compile libmount from util-linux but can not figure out where to put it or how to specify where should meson look for it.

There is a 'mount-path' option, but even when providing it it still says:

Meson encountered an error in file meson.build, line 797, column 0:                                                    
Cross dependency 'mount' not found

My cross compile file looks like this:

[binaries]                   
c = '/usr/bin/arm-linux-gnueabi-gcc'                       
cpp = '/usr/bin/arm-linux-gnueabi-g++'                     
ar = '/usr/arm-linux-gnueabi/bin/ar'                       
strip = '/usr/arm-linux-gnueabi/bin/strip'                 
pkgconfig = '/usr/bin/arm-linux-gnueabi-pkg-config'        

[host_machine]               
system = 'linux'             
cpu_family = 'arm'           
cpu = 'cortex-m4'            
endian = 'little'            

[build_machine]              
system = 'linux'             
cpu_family = 'x86_64'        
cpu = 'i686'                 
endian = 'little' 

Btw if you know about another way to get systemd on arm without this ridiculous(IMHO) setup it would be nice.

Thank you.

Dalbenn
  • 117
  • 2
  • 12

1 Answers1

3

Meson uses pkg-config tool to find dependencies. This tool searches, so called, package config files using PKG_CONFIG_PATH environment variable. You can check that there is no mount in:

$ pkg-config --list-all

This is naturally because you've just compiled but did not provide package config file mount.pc to be found. Check libmount sources, it should contain mount.pc.in that is used by installation process. In cross-compiling case, it should be turned into mount.pc manually according to guide.

After creating package config file you should be able to successfully run:

$ pkg-config --validate mount

You can also check validness of variables:

$ pkg-config --cflags mount
-I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/libmount -I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/blkid -I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/uuid

$ pkg-config --libs mount  
-lmount

BTW, this is the contents of mount.pc that I've got:

prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include

Name: mount
Description: mount library
Version: 2.29.1
Requires.private: blkid
Cflags: -I${includedir}/libmount
Libs: -L${libdir} -lmount

Btw if you know about another way to get systemd on arm without this ridiculous(IMHO) setup it would be nice.

systemd switched to meson, so now it's only the way, unless you want to build older version with autotools.

But thinking wider, you can also take a look at yocto which focuses on simplifying getting cross-compiled linux distributions.


Update

As, @Yasushi Shoji correctly pointed out, for cross-compilation case, PKG_CONFIG_LIBDIR should be used instead, as it prevents undesired/wrong usage of local system packages, check this.

pmod
  • 10,450
  • 1
  • 37
  • 50
  • 2
    Note that "_`pkg-config` will **additionally** look in the [...] directories specified by the `PKG_CONFIG_PATH`_". This means that "_The default directory will always be searched_", and it might find native version of .pc files. It'd be better, IMO, to use `PKG_CONFIG_LIBDIR` instead. See `pkg-config(1)` for more details. – Yasushi Shoji Feb 10 '18 at 06:21
  • Hey, that's pretty handy. Thanks. Now I get "Could not generate cargs for mount:" error on the same line. But that's a story for another time I guess. – Dalbenn Feb 12 '18 at 09:14
  • @Dalbenn thanx, Ok, but that may be related.... looks like something wrong with --cflags, can you post mount.pc file somewhere? – pmod Feb 12 '18 at 09:41
  • I am sorry, can't look into this anymore. We went another way. But thank you anyway! – Dalbenn Mar 07 '18 at 13:48
  • 2
    I just wanted to add the libmount is part of [utils-linux](https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/) – ChrisG Apr 18 '19 at 13:39
  • Hi pmod, yashushi shoji. I tried PKG_CONFIG_LIBDIR, but still can't get past the 'mount' dependency. would compile so easily for x86, but when it comes to cross compiling for arm, im just not able to get past this. – badri May 03 '20 at 23:53
  • my mount.pc looks like this - Name: mount Description: mount library Version: 2.35.0 Requires.private: blkid Cflags: -I/home/badri/sandboxes/secup/secup_refresh/util-linux/include/libmount Libs: -L/home/badri/sandboxes/secup/secup_refresh/util-linux/usr/lib -lmount and likewise for blkid.pc – badri May 04 '20 at 00:00
  • im running using this cmd - meson --cross-file cross_file.txt builddir --prefix=/home/badri/arm_libs/meson_trial --libdir=/home/badri/arm_libs/meson_trial/lib where /home/badri/arm_libs/meson_trial/lib/mountpc/ contains mount.pc and blkid.pc – badri May 04 '20 at 00:03
  • my crossfile.txt contents look like this -[host_machine] system = 'linux' cpu_family = 'arm' cpu = 'aarch64' endian = 'little' [properties] c_args = [] c_link_args = [] [binaries] c = 'aarch64-linux-gnu-gcc' cpp = 'aarch64-linux-gnu-g++' ar = 'aarch64-linux-gnu-ar' ld = 'aarch64-linux-gnu-ld' objcopy = 'aarch64-linux-gnu-objcopy' strip = 'aarch64-linux-gnu-strip' pkgconfig = 'aarch64-linux-gnu-pkg-config' – badri May 04 '20 at 00:04
  • i even tried adding pkg_config_libdir = /home/badri/arm_libs/meson_trial/lib where my mountpc is located. this doesnt work eventhough i have meson version 0.54.1 and i would get the error "ERROR: Malformed value in cross file variable pkg_config_libdir." – badri May 04 '20 at 00:07
  • pkg-config --cflags mount is giving me the correct output. but meson always complains that meson.build:1815:2: ERROR: Dependency "mount" not found, tried pkgconfig – badri May 04 '20 at 00:09
  • @badri pkg_config_libdir , or actually PKG_CONFIG_LIBDIR, the same as PKG_CONFIG_PATH are environment variables, so you should set it in your shell with $ export PKG_CONFIG_LIBDIR=/home/badri/arm_libs/meson_trial/lib – pmod May 04 '20 at 06:42
  • 1
    @badri then it's strange that you have "ERROR: Malformed value in cross file ... " but I noticed another thing. Typically .pc file should be in .../pkgconfig directory but that is not mandatory, the important thing that .pc files must be in directory(ies) that pointed by PKG_CONFIG_LIBDIR, i.e. in your case PKG_CONFIG_LIBDIR should contain /home/badri/arm_libs/meson_trial/lib/mountpc or .pc files needs to be move one directory up – pmod May 04 '20 at 10:11
  • Hi @pmod, I tried all of them. put the .pc files in a folder called /home/badri/arm_libs/meson_trial/pkgconfig and set the same to PKG_CONFIG_LIBDIR. Even tried using with and without the variable pkg_config_libdir. just coincidentally, it complains of malformedness only if i had it in the cross_file.txt. It seems to be ok (even before) if i provide it in the command line like this - meson --cross-file cross_file.txt builddir --prefix=/home/badri/arm_libs/meson_trial --libdir=/home/badri/arm_libs/meson_trial/pkgconfig – badri May 04 '20 at 14:21
  • 1
    @badri then you should have $ export PKG_CONFIG_LIBDIR=/home/badri/arm_libs/meson_trial/pkgconfig (previously you mentioned another dir), you don't need anything else , do not put pkg_config_libdir to cross file (that's invalid keyword for it) and don't use --libdir in cmd line. Just set env. variable and you need to re-setup your build dir, easier if you remove it and then setup again with $ meson --cross-file cross_file.txt builddir --prefix=/home/badri/arm_libs/meson_trial – pmod May 04 '20 at 15:24
  • Thanks a lot pmod. you helped me persevere! I set PKG_CONFIG_LIBDIR (and also PKG_CONFIG_PATH) and it has worked. I noticed that there were two pkg-config binaries in my toolchain for arm namely aarch64-linux-gnu-pkg-config-real and aarch64-linux-gnu-pkg-config. I made the variables in my cross-file.txt point to the "real" one and it worked. No wonder it was called "real". I suspect that this could have been the real issue. – badri May 04 '20 at 18:06