简体   繁体   English

在 pkg-config 和 cmake 找不到介子中声明库依赖项

[英]declare library dependency in meson not found by pkg-config and cmake

This question is related to the meson build system, specifically how to add an external dependency (library) which is not found by pkg-config and / or cmake.这个问题与介子构建系统有关,特别是如何添加 pkg-config 和/或 cmake 找不到的外部依赖项(库)。 This should be simple but it seems I am missing something (obvious?.).这应该很简单,但似乎我遗漏了一些东西(很明显?。)。

Say I have a static library somewhere in a custom path /home/user/libraries/foo/lib/libfoo.a with a corresponding include directory /home/user/libraries/foo/include/ .假设我在自定义路径/home/user/libraries/foo/lib/libfoo.a的某处有一个 static 库,并带有相应的包含目录/home/user/libraries/foo/include/ As this library is not found by pkg-config and / or cmake, doing something like由于 pkg-config 和/或 cmake 找不到此库,因此执行类似的操作

foo_dep = dependency('foo')
exe = executable('bar','bar.cpp', link_with: foo_dep)

will not work.不管用。 So I am wondering what the meson way of doing things is, ie should I use declare_dependency() (although I thought that this is more for subprojects), should I pass compiler and linker flags with -I and -L -l etc. (although that would mean specifying hard links which may be maintained manually which can't be the preferred way) or is there a better way out there for doing this?所以我想知道介子的做事方式是什么,即我应该使用declare_dependency() (尽管我认为这更适用于子项目),我是否应该使用-I-L -l等传递编译器和 linker 标志(虽然这意味着指定可以手动维护的硬链接,这不是首选方式)还是有更好的方法来做到这一点?

You use the find_library() and has_header() methods on the compiler object: https://mesonbuild.com/Reference-manual.html#compiler-object您在编译器 object 上使用find_library()has_header()方法: https://mesonbuild.com/Reference-manual.html#compiler-object

Then pass that to whatever you are compiling.然后将其传递给您正在编译的任何内容。

cxx = meson.get_compiler('cpp')
libfoo = cxx.find_library('foo')
executable('foo', 'foo.cpp',
  link_with: libfoo,
  include_directories: ..., # Using has_header() find this path
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM