ld 从源代码构建 Valgrind 时找不到 -lmpi

问题描述 投票:0回答:1

我正在尝试从源代码构建 Valgrind 3.21.0,我下载了存档here并按照自述文件中的说明进行操作:

  1. 运行./configure
  2. 运行“make”
  3. 运行“make install”,如果目标权限足够的话,可以以 root 身份运行 需要那个。

当我运行“make”命令时,出现此错误:

make[3]: Entering directory '/opt/valgrind-3.21.0/memcheck'
../coregrind/link_tool_exe_linux 0x58000000 mpicc     -o memcheck-amd64-linux  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-signedness -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wenum-conversion -Wimplicit-fallthrough=2 -Wold-style-declaration -finline-functions -fno-stack-protector -fno-strict-aliasing -fno-builtin   -fomit-frame-pointer -O2 -static -nodefaultlibs -nostartfiles -u _start -Wl,--build-id=none -m64 memcheck_amd64_linux-mc_leakcheck.o memcheck_amd64_linux-mc_malloc_wrappers.o memcheck_amd64_linux-mc_main.o memcheck_amd64_linux-mc_main_asm.o memcheck_amd64_linux-mc_translate.o memcheck_amd64_linux-mc_machine.o memcheck_amd64_linux-mc_errors.o ../coregrind/libcoregrind-amd64-linux.a ../VEX/libvex-amd64-linux.a -lgcc ../coregrind/libgcc-sup-amd64-linux.a 
/usr/bin/ld: cannot find -lmpi: No such file or directory
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:1133: memcheck-amd64-linux] Error 1
make[3]: Leaving directory '/opt/valgrind-3.21.0/memcheck'
make[2]: *** [Makefile:1444: all-recursive] Error 1
make[2]: Leaving directory '/opt/valgrind-3.21.0/memcheck'
make[1]: *** [Makefile:914: all-recursive] Error 1
make[1]: Leaving directory '/opt/valgrind-3.21.0'
make: *** [Makefile:777: all] Error 2

看起来 ld 找不到 -lmpi,但我安装了 OpenMPI 4.2.1,当我运行

ld -lmpi --verbose
时,ld 正确找到所有文件。

我使用的是 Ubuntu 22.04,我无法使用默认的 valgrind (v3.18.1),因为当我尝试使用它时,我收到一个无法解决的错误:

==48326== Memcheck, a memory error detector
==48326== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==48326== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==48326== Command: ./spheres
==48326== 
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x23
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x23
==48326== Valgrind: debuginfo reader: ensure_valid failed:
==48326== Valgrind:   during call to ML_(img_get)
==48326== Valgrind:   request for range [1279783701, +4) exceeds
==48326== Valgrind:   valid image size of 113115128 for image:
==48326== Valgrind:   "/usr/local/lib/libvtkCommonCore-9.1.so.9.1.0"
==48326== 
==48326== Valgrind: debuginfo reader: Possibly corrupted debuginfo file.
==48326== Valgrind: I can't recover.  Giving up.  Sorry.
==48326==

我的一个朋友在使用 Valgrind 3.18.1 时也遇到了同样的问题,但他通过从源代码构建 Valgrind 3.21.0 来避免了这个问题。感谢您阅读这篇文章,我希望我能在这里找到解决方案。

[编辑] 我尝试 grep 所有 valgrind 文件中 -lmpi 的位置,并在我的 config.log 中发现这些可疑行:

configure:6817: checking for a supported CPU
configure:6844: result: ok (x86_64)
configure:6941: checking for a 64-bit only build
configure:6956: result: no
configure:6960: checking for a 32-bit only build
configure:6975: result: no
configure:6988: checking for a supported OS
configure:6996: result: ok (linux-gnu)
configure:7001: checking for the kernel version
configure:7014: result: 2.6 or later (6.2.0-26-generic)
configure:7325: checking for 32 bit build support
configure:7343: mpicc -o conftest -m32   conftest.c  >&5
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so when searching for -lmpi
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libmpi.so when searching for -lmpi
/usr/bin/ld: cannot find -lmpi: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so when searching for -lmpi
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libmpi.so when searching for -lmpi
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory

但最后,configure命令没有抱怨,它以状态0退出。只有当我运行make时才会出现问题,所以我不知道这些行是否与问题有关。我认为 ./configure 只是尝试以 32 位进行编译,但它不起作用,但这是正常行为。

我不知道我现在应该做什么。

mpi valgrind
1个回答
0
投票

我终于找到了解决办法。在

make
期间引起问题的命令以
../coregrind/link_tool_exe_linux 0x58000000 mpicc 
开头,其中 mpicc 是我的默认 C 编译器。此 mpicc 命令是一个调用 gcc 的包装器,带有附加标志:
gcc -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi
。这里是在make命令期间找不到的
-lmpi
(虽然用mpicc运行一个简单的MPI程序没有问题)。正如 @GillesGouaillardet 评论所解释的,我的 MPI 实现仅为 64 位,我正在尝试为 32 位和 64 位构建 valgrind。

所以我找到的简单解决方案是直接使用 gcc 而不是 mpicc :

export CXX=g++ && export CC=gcc

然后重新运行

./configure
make
make install

正如 @GillesGouaillardet 和 @PaulFloyd 在他们的评论中建议的那样,另一个解决方案应该是寻找

./configure
选项来构建仅适用于 64 位的 valgrind。

谢谢大家的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.