MesonBuild: How to define dependency to a library that cannot be found by `pkg-config`?

做~自己de王妃 提交于 2019-12-07 00:51:43

问题


My project (in C) has a third party dependency at build time. But the third party library is, by default, installed to /opt/ instead of /lib, and I cannot find it in pkg-config. From mesonbuild's documentation, should I use declare_dependency, I don't have its source code to treat it as my sub-project. If I use dependency() to define it, I can't find the correct argument to define a customized location.

How to declare dependency for a non-standard third party library?


回答1:


As documented here and here

The main use case for this [declare_dependency()] is in subprojects.

and

[dependency()] finds an external dependency ... with pkg-config [or] library-specific fallback detection logic ...

You can, instead, use find_library() provided by the compiler object and include_directories() . find_library() returns an object just like the one declare_dependency() returns. include_directories() returns an opaque object which contains the directories.

Assuming you are using a C compiler and your 3rd party library and its header file are /opt/hello/libhello.so and /opt/hello/hello.h, you can do:

project('myproj', 'c')

cc = meson.get_compiler('c')
lib_hello = cc.find_library('hello',
               dirs : ['/opt/hello'])
inc_hello = include_directories('/opt/hello')
exec = executable('app',
                  'main.c',
                  dependencies : [lib_hello],
                  include_directories : inc_hello)


来源:https://stackoverflow.com/questions/47010355/mesonbuild-how-to-define-dependency-to-a-library-that-cannot-be-found-by-pkg-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!