mpivalgrind

ld cannot find -lmpi when building Valgrind from source


I'm trying to build Valgrind 3.21.0 from source, I downloaded the archive here and followed the instructions in the README :

  1. Run ./configure
  2. Run "make"
  3. Run "make install", possibly as root if the destination permissions require that.

When I run the "make" command, I get this error :

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

It seems ld cannot find -lmpi, but I have OpenMPI 4.2.1 installed and when I run ld -lmpi --verbose, ld finds all files correctly.

I am on Ubuntu 22.04, and I can't use default valgrind (v3.18.1) because I get an error that I couldn't solve either when I try to use it :

==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==

A friend of mine has the same problem with Valgrind 3.18.1 but he avoided it by building Valgrind 3.21.0 from source. Thank you for reading this post, I hope I'll find a solution here.

[EDIT] I tried to grep where -lmpi was in all valgrind files, and found in my config.log these suspicious lines :

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

but at the end, the configure command doesn't complain, it exits with status 0. It's only when I run make that the problem occurs so I don't know if these lines are related to the problem. I think the ./configure is just trying to compile in 32bits and it doesn't work but this is a normal behavior.

I'm not sure what I should do now.


Solution

  • I finally found a solution. The command causing trouble during make starts with ../coregrind/link_tool_exe_linux 0x58000000 mpicc where mpicc is my default C compiler. This mpicc command is a wrapper calling gcc with additional flags : 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. And here is the -lmpi that cannot be found during the make command (while there is no problem running a simple MPI program with mpicc). As explained in @GillesGouaillardet's comment, my MPI implementation is 64 bits only and I'm trying to build valgrind for both 32 and 64 bits.

    So the simple solution I found was to use gcc directly instead of mpicc :

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

    Then rerun ./configure, make and make install.

    As @GillesGouaillardet and @PaulFloyd suggested in their comments, another solution should be to look for the ./configure options to build valgrind for 64 bits only (if it is the root of the problem).

    Thank you all for your help.