meson
meson copied to clipboard
cc.find_library(...).as_system() throws "Unknown method" error
Calling compler.find_library(...).as_system() fails with the following error:
meson.build:3:42: ERROR: Unknown method "as_system" in object <[ExternalLibraryHolder] holds [ExternalLibrary]: <ExternalLibrary m: True>> of type ExternalLibraryHolder.
However, according to the dep documentation, compiler.find_library() is supposed to return a dep object, that has the as_system() method.
The more complete use-case I have, is to allow specifying the path to a mingw-build of GLUT when cross-compiling, while converting the include path to a system include (-isystem) so the code still can include <GL/glut.h>. The build of GLUT I have ships without .pc files, so I can't really use a dependecy() here...
glut_libdir = []
glut_incdir = []
with_glut = get_option('with-glut')
if with_glut != ''
glut_libdir = with_glut / 'lib'
glut_incdir = with_glut / 'include'
endif
dep_glut = cc.find_library(
'glut',
dirs: glut_libdir,
has_headers: 'GL/glut.h',
header_include_directories: include_directories(glut_incdir)).as_system()
To Reproduce
Try compiling this project
project('meson-repro', 'c')
meson.get_compiler('c').find_library('m').as_system()
Expected behavior
I expect the as_system() function to work, as the documentation suggests
system parameters
- Happens for both when cross-compiling and when building native
- Debian Sid
- Python 3.10.4
- Meson 0.62.0
- Ninja 1.10.1
Just to be clear, I'm aware that I can do include_directories(glut_incdir, is_system: true) instead, I just wanted to report this issue!
find_library() doesn't produce a dep object that has an include_directories() object as part of its interface. The as_system() method mutates the include_directories aspect of a dependency.
No, using header_include_directories does NOT make the returned ExternalLibrary object have an include_directories interface to mutate.
Since ExternalLibrary doesn't have anything for as_system to modify it makes no sense for it to allow such a method. The documentation is at fault for implying that a dependency() and a find_library() are identical -- they are not, even if the latter can generally be passed to any kwarg that accepts the former.
Yeah, I guess it's fair to say that this is a documentation bug, then.
I am new to meson and also came accross this issue since the documentation is still wrong about this topic. :(
So the solution is to use cc.find_library like this:
glut_incdir = 'some/path/to/headers'
dep_glut = cc.find_library(
'glut',
dirs: glut_libdir,
has_headers: 'GL/glut.h',
header_include_directories: include_directories(glut_incdir, is_system: true))
That does not work in all cases, see https://github.com/mesonbuild/meson/issues/13611 Thank you for your support!