在 pkg-config 和 cmake 找不到的介子中声明库依赖
declare library dependency in meson not found by pkg-config and cmake
这个问题与介子构建系统有关,特别是如何添加 pkg-config 和/或 cmake 找不到的外部依赖项(库)。这应该很简单,但似乎我遗漏了一些东西(很明显?!)。
假设我在自定义路径 /home/user/libraries/foo/lib/libfoo.a
中的某处有一个静态库,具有相应的包含目录 /home/user/libraries/foo/include/
。由于 pkg-config 和/或 cmake 找不到此库,因此执行类似
的操作
foo_dep = dependency('foo')
exe = executable('bar','bar.cpp', link_with: foo_dep)
将不起作用。所以我想知道 meson 做事的方式是什么,即我应该使用 declare_dependency()
(尽管我认为这更适用于子项目),我是否应该通过编译器和链接器带有 -I
和 -L -l
等的标志(尽管这意味着指定可以手动维护的硬链接,这不是首选方式)或者是否有更好的方法可以做到这一点?
您在编译器对象上使用了 find_library()
和 has_header()
方法:https://mesonbuild.com/Reference-manual.html#compiler-object
然后将其传递给您正在编译的任何内容。
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
)
这个问题与介子构建系统有关,特别是如何添加 pkg-config 和/或 cmake 找不到的外部依赖项(库)。这应该很简单,但似乎我遗漏了一些东西(很明显?!)。
假设我在自定义路径 /home/user/libraries/foo/lib/libfoo.a
中的某处有一个静态库,具有相应的包含目录 /home/user/libraries/foo/include/
。由于 pkg-config 和/或 cmake 找不到此库,因此执行类似
foo_dep = dependency('foo')
exe = executable('bar','bar.cpp', link_with: foo_dep)
将不起作用。所以我想知道 meson 做事的方式是什么,即我应该使用 declare_dependency()
(尽管我认为这更适用于子项目),我是否应该通过编译器和链接器带有 -I
和 -L -l
等的标志(尽管这意味着指定可以手动维护的硬链接,这不是首选方式)或者是否有更好的方法可以做到这一点?
您在编译器对象上使用了 find_library()
和 has_header()
方法:https://mesonbuild.com/Reference-manual.html#compiler-object
然后将其传递给您正在编译的任何内容。
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
)