使用Meson时如何指定库路径? [英] How can I specify library path when using Meson?

查看:590
本文介绍了使用Meson时如何指定库路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图用Meson构建一个c ++项目.

I'm trying to build a c++ project with Meson.

问题是,我在/opt/conda 下有一些库但无法确定在运行介子构建时如何链接项目.它似乎只在/usr/lib 目录中搜索.

The thing is, I have some libraries under /opt/conda but can't figure out how to link the project when running meson build. It seems to be only searching through /usr/lib directory.

据我了解,介子使用 cmake pkg-config 查找库.那么设置类似 CMAKE_PREFIX_PATH 的方法是否可行?如果是这样,我该怎么办?

As far as I understood, meson uses cmake and pkg-config to look for libraries. Then would setting something like CMAKE_PREFIX_PATH be a feasible solution? and if so, how can I do that?

谢谢.

推荐答案

我看到了两种可能的方法来解决您的问题.

I see two possible approaches to solve your problem.

  • 第一个解决方案使用 LIBRARY_PATH ,这与 LD_LIBRARY_PATH 不同,如稍后所述.
  • 第二个解决方案使用修改后的介子文件将选项直接传递给链接器.(可选)它还使用 rpath ,从而无需在以后修改 LD_LIBRARY_PATH .

  • the first solution uses LIBRARY_PATH, which is different from LD_LIBRARY_PATH as explained later.
  • the second solution uses a modified meson file to directly pass options to the linker. Optionally, it also uses rpath that eliminates the need to modify LD_LIBRARY_PATH afterward.

  1. 第一个解决方案

在构建项目时,链接器使用 LIBRARY_PATH (而不是 LD_LIBRARY_PATH )

When building your project the linker use LIBRARY_PATH (and not LD_LIBRARY_PATH)

gcc在编译之前使用

LIBRARY_PATH 来搜索目录包含需要链接到您的静态库和共享库程序.

LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program.

LD_LIBRARY_PATH 搜索目录成功编译后包含共享库并链接.

LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked.

更多详细信息: LD_LIBRARY_PATH与LIBRARY_PATH

也许您可以尝试

export LIBRARY_PATH=/opt/conda/:$LIBRARY_PATH

在运行介子来构建项目之前.

before running meson to build your project.

  1. 第二个解决方案

修改介子文件并使用 rpath (可选)

Modifying your meson file and use rpath (optional)

先前第一个解决方案的替代方法是直接修改您的Meson文件,以将某些选项传递给链接器.

An alternative to the previous first solution is to directly modify your Meson file to pass some options to the linker.

这是我过去使用过的东西,可以很容易地适应您的问题:

Here is something I used in the past you can easily adapt to your problem:

#
# blaspp
#
blaspp_lib = 'blaspp'
blaspp_lib_dir = '/opt/slate/lib'
blaspp_header_dir = '/opt/slate/include'

blaspp_dep = declare_dependency(
    link_args : ['-L' + blaspp_lib_dir, '-l' + blaspp_lib],
    include_directories : include_directories(blaspp_header_dir))

executable('test_blaspp',
       'test_blaspp.cpp',
       build_rpath : blaspp_lib_dir,
       install_rpath : blaspp_lib_dir,
       dependencies : [blaspp_dep])

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆