我的项目(在 C 中)在构建时具有第三方依赖性。但是第三方库默认安装到/opt/
而不是/lib
,我在pkg-config
中找不到它.从mesonbuild
的文档来看,我是否应该使用declare_dependency
,我没有它的源代码来把它当作我的子项目。如果我使用 dependency()
来定义它,我找不到正确的参数来定义自定义位置。
如何声明对非标准第三方库的依赖?
最佳答案
The main use case for this [
declare_dependency()
] is in subprojects.
和
[
dependency()
] finds an external dependency ... withpkg-config
[or] library-specific fallback detection logic ...
您可以改为使用 find_library()
由编译器
提供
对象和 include_directories()
. find_library()
返回一个对象,就像 declare_dependency()
返回的对象一样。 include_directories()
返回一个包含目录的不透明对象。
假设您使用的是 C 编译器,您的第 3 方库及其头文件是 /opt/hello/libhello.so
和 /opt/hello/hello.h
,你可以这样做:
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)
关于c - 介子构建 : How to define dependency to a library that cannot be found by `pkg-config` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47010355/