Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

meson-build

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.
like image 885
Picaud Vincent Avatar asked Jan 16 '20 12:01

Picaud Vincent


2 Answers

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)
like image 87
Clinten Gomez Avatar answered Sep 22 '22 18:09

Clinten Gomez


I finally got a solution, one must use LIBRARY_PATH

export LIBRARY_PATH=/opt/MyDepedence/lib
meson build

Note: attention this is not LD_LIBRARY_PATH, see there for the difference

Also read this Meson/issues/217 . For Windows, the LIBRARY_PATH equivalent seems to be LIBPATH (but I was not able to check as I only run under Linux).


An alternative is to "manually" define a new dependence. In your Meson project:

project('Test, ['cpp'])

myLib_dep = declare_dependency(link_args : ['-L/opt/MyDependence/lib', '-lmyLib'],
                               include_directories : ['/opt/MyDependence/include'])


exe1 = executable('main', ['main.cpp'], dependencies : [myLib_dep])

A refinement that could be done is to store this "manual" setting into meson_options.txt.


Note: I finally answered my question, but I am still open to better solutions.

like image 36
Picaud Vincent Avatar answered Sep 21 '22 18:09

Picaud Vincent