Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pkg-config fails to find package under sysroot directory

Can anyone please tell me why this might fail:

afeder@ubuntu:~/android/toolchain/sysroot$ ls $PKG_CONFIG_SYSROOT_DIR/usr/local/lib/pkgconfig/mozjs185.pc
/home/afeder/android/toolchain/sysroot/usr/local/lib/pkgconfig/mozjs185.pc

afeder@ubuntu:~/android/toolchain/sysroot$ pkg-config mozjs185 --cflags
Package mozjs185 was not found in the pkg-config search path.
Perhaps you should add the directory containing `mozjs185.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mozjs185' found

According to man pkg-config(1), /usr/local/lib/pkgconfig is supposed to be one of the default search paths.

like image 787
Anders Feder Avatar asked Dec 01 '22 23:12

Anders Feder


1 Answers

I found the answer here: http://www.flameeyes.eu/autotools-mythbuster/pkgconfig/cross-compiling.html

The wrapper script should not only set the PKG_CONFIG_SYSROOT_DIR variable: when cross-compiling you want to ignore the packages installed in the system, and instead rely only on those installed in the cross-compiled environment. This is achieved by resetting PKG_CONFIG_DIR (which lists additional search paths), and at the same time setting PKG_CONFIG_LIBDIR to override the default base search paths.


The resulting CMake File would be something like this:

set(CMAKE_SYSROOT "/path/to/sysroot")

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

Disclaimer: I used the CMAKE_SYSROOT variable which is useful when you want to pass -sysroot to g++. If you don't want this you should name your variable differently.

like image 77
Anders Feder Avatar answered Dec 16 '22 04:12

Anders Feder