Search code examples
meson-build

Meson: how to make find_library() works with an unusual path?


For my Meson project I have a dependency that is in an "unusual" place:

/opt/MyDependence/lib/libmyLib.so
/opt/MyDependence/include/myLib.hpp

My meson file is:

project('Test', ['cpp'])

cpp = meson.get_compiler('cpp')
myLib_dep = cpp.find_library('myLib', required: true)

Obviously Meson cannot find the library

Meson.build:5:0: ERROR: C++ library 'myLib' not found

The problem is that I do not know the "canonical" way to add extra search paths so that Meson can found my lib. Any idea?


update: please note that even if I use:

meson --libdir=/opt/MyDepedence/lib build

I get this error message:

meson.build:1:0: ERROR: The value of the 'libdir' option is '/opt/MyDepedence/lib' which must be a subdir of the prefix '/usr/local'.
Note that if you pass a relative path, it is assumed to be a subdir of prefix.

Solution

  • find_library now has an optional argument dirs (since 0.53.0) that indicates an extra list of absolute paths where to look for program names.

    cpp = meson.get_compiler('cpp')
    myLib_dep = cpp.find_library('myLib', dirs: '/opt/MyDepedence/lib', required: true)