首页 > 解决方案 > 在使用 make 制作的文件上使用 Valgrind

问题描述

我正在尝试在一个程序上使用 valgrind,该程序是使用此 makefile 的 make 命令的输出:

# Intlist makefile

P = intlist
C = g++
F = -m32 -g -O0 -Wall
O = IntListTest.o IntList.o

$(P): $(O)
    $(C) $(F) -o $(P) $(O)

IntListTest.o: IntListTest.cpp IntList.h
    $(C) $(F) -c IntListTest.cpp

IntList.o: IntList.cpp IntList.h
    $(C) $(F) -c IntList.cpp

clean:
    rm $(P) $(O)

当我在 intlist 上运行 valgrind 时,它会生成:

==130929== Memcheck, a memory error detector
==130929== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==130929== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==130929== Command: intlist
==130929==

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld-linux.so.2
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux.so.2
valgrind:
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:
valgrind:  Cannot continue -- exiting now.  Sorry.

我觉得我的 makefile 有问题,但我不确定它是什么。任何想法都非常感谢。但是,这发生在我无权安装任何东西的大学拥有的服务器上,所以这不是我的解决方案。

标签: c++linuxmakefilevalgrind

解决方案


You are building a 32bit executable (the -m32 option in your compile/link lines) but from the output valgrind provides, you don't have all the support libraries available to run valgrind on a 32bit executable.

Do you really need your program to be 32bit? If not the simplest thing to do is remove the -m32 option and clean and rebuild everything.

If you really have to have a 32bit binary then read the output valgrind provides above carefully to determine what extra 32bit libraries you're missing and need to install.


推荐阅读