c - 介子构建 : How to define dependency to a library that cannot be found by `pkg-config` ?

标签 c dependencies meson-build

我的项目(在 C 中)在构建时具有第三方依赖性。但是第三方库默认安装到/opt/而不是/lib,我在pkg-config中找不到它.从mesonbuild的文档来看,我是否应该使用declare_dependency,我没有它的源代码来把它当作我的子项目。如果我使用 dependency() 来定义它,我找不到正确的参数来定义自定义位置。

如何声明对非标准第三方库的依赖?

最佳答案

记录在案herehere

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

[dependency()] finds an external dependency ... with pkg-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/

相关文章:

c - 访问未定义的外部数组

c - PCRE 获取匹配位置而不获取所有匹配项

java - 依赖 "test"范围是否适用于 Maven 中的 "integration-test"阶段?

qt-creator - 如何使用 Qt Creator 设置介子

python - 如何从 Meson 启动外部 Python 程序?

c - 位破解 : Expanding bits

c - linux/list.h - 如何安全地从列表中删除项目?

postgresql - 如何在 ubuntu 14.04 中安装 postgis 1.5?

gradle - 如何处理libgdx中的独立依赖项?

python - Meson 找不到 pykeepass 模块,我确定它已安装