c++ - 介子找不到交叉编译库

标签 c++ linux cross-compiling meson-build

我正在使用 meson 构建我的项目。

构建原生时 - 一切正常。 meson 能够找到所有依赖项,并创建可执行文件。

当使用 aarch 交叉文件时 - 依赖关系不起作用...

这是我的meson.build:

# builds the project and copies all relevant data files
project(
  'demo',
  'cpp',
  default_options : [
    'cpp_std=c++20',
  ],
  version: run_command('cat', '.version', check: true).stdout().strip(),
)

################
# dependencies #
################
dependencies = [
  dependency('CLI11'),
  dependency('nlohmann_json'),
  dependency('spdlog'),
  meson.get_compiler('cpp').find_library('MY_LIB')
]

##############
# executable #
##############
executable(
  'demo',
  files('src'),
  dependencies : dependencies,
  install : true,
)

这是我的交叉文件 (aarch64.ini):

; arm 64 bit little endian
[binaries]
cpp = 'aarch64-none-linux-gnu-g++'
strip = 'aarch64-none-linux-gnu-strip'
pkg-config = 'aarch64-none-linux-gnu-pkg-config'

我使用 meson setup --cross-file aarch64.ini aarch64

进行编译

我已经安装了相关的交叉编译器 (g++-11),及其所有相关的二进制文件 + 编辑了我的 PATH 以便将它们包括在内。

这是我的错误:

meson.build:14:0: ERROR: C++ shared or static library 'MY_LIB' not found

A full log can be found at ... meson-logs/meson-log.txt

我试过把相关的lib文件放在

  1. 继续前进
  2. /usr/lib/
  3. /usr/lib/arm/64/(并编辑了 find_library 函数以包含该目录)

我还尝试在没有版本的情况下复制它/链接它(即尝试了 MY_LIB.so.4.8.1 和 MY_LIB.so)

没有任何作用...

我尝试链接的库格式正确:

$ file MY_LIB.so.4.8.1 
MY_LIB.so.4.8.1: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=457ef064499398e8ffe4657e60fe44f30cb7db51, not stripped

我应该寻找什么才能解决这个问题?

我的想法:

  1. 也许我的定义(我的交叉文件)与我链接的库不匹配?我尝试使用 file 验证它,但也许我错了?
  2. 也许编译器名称中的 none 是个问题(不应该只是 aarch-linux-gnu 吗?)
  3. 也许我的 pkg-config 有问题? (我没有 aarch64...pkg-config。有吗?)

最佳答案

是否有 MY_LIB.so 到 MY_LIB.so.4.8.1 的符号链接(symbolic link)? 您也可以尝试以这种方式包含依赖项:

myLibDep = declare_dependency(
    link_args : ['<my lib path>/MY_LIB.so']) 

....

dependencies = [
  dependency('CLI11'),
  dependency('nlohmann_json'),
  dependency('spdlog'),
  myLibDep,
]

关于c++ - 介子找不到交叉编译库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73269340/

相关文章:

c++ - 带有 -isysroot 的 gcc 创建包含以等号 "="开头的包含路径并且编译失败

c++ - 如何获取函数的地址?

c++ - 在 C 或 C++ 中获取系统语言

linux - 如何获取进程 ID 以杀死 nohup 进程?

mysql - 如何从mysql查询结果中删除+-----+

clang - 你如何为自己组装一个交叉编译器?

docker - 从 Ubuntu amd64 到 arm7l : exec user process caused "exec format error" 进行交叉编译

c++ - G++ 链接到 Cygwin 中的 psapi

c++ - 按住键盘输入时犹豫?

r - 无法从 Linux 终端看到 R 帮助文件