首页 > 解决方案 > 如何解决“链接器命令失败,退出代码 1”问题?

问题描述

我正在尝试使用OMPTrace哪个工具来跟踪和可视化OpenMP程序执行,如此处所示https://github.com/passlab/omptrace示例中给出的代码是用C. (jacobi.caxpy.c)该库已很好地安装在/home/hakim/llvm-openmp/BUILD/omptrace/build/libomptrace.so. 我创建了一个makefile如下:

OMP_INSTALL=/home/hakim/llvm-openmp-install
OMP_LIB_PATH=${OMP_INSTALL}/lib
OMPTRACE_LIB=/home/hakim/llvm-openmp/BUILD/omptrace/build/libomptrace.so

default:runaxpy

axpyclang: axpy.c
    clang -g -fopenmp axpy.c -o axpyclang
    objdump -d axpyclang >axpyclang.objdump

jacobi: jacobi.c
    clang -g -fopenmp jacobi.c -o jacobi -lm
    objdump -d jacobi >jacobi.objdump

runaxpy: axpyclang
    LD_PRELOAD=${OMP_LIB_PATH}/libomp.so:${OMPTRACE_LIB} ./axpyclang 1024   

runjacobi: jacobi
    LD_PRELOAD=${OMP_LIB_PATH}/libomp.so:${OMPTRACE_LIB} ./jacobi

clean:
    rm axpyclang axpyclang.objdump core jacobi jacobi.objdump

执行它时,我得到:

clang -g -fopenmp axpy.c -o axpyclang
axpy.c:18:5: warning: 'ftime' is deprecated [-Wdeprecated-declarations]
    ftime(&tm);
    ^
/usr/include/x86_64-linux-gnu/sys/timeb.h:40:19: note: 'ftime' has been explicitly marked deprecated here
  __nonnull ((1)) __attribute_deprecated__;
                  ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:251:51: note: expanded from macro '__attribute_deprecated__'
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
                                                  ^
axpy.c:25:5: warning: 'ftime' is deprecated [-Wdeprecated-declarations]
    ftime(&tm);
    ^
/usr/include/x86_64-linux-gnu/sys/timeb.h:40:19: note: 'ftime' has been explicitly marked deprecated here
  __nonnull ((1)) __attribute_deprecated__;
                  ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:251:51: note: expanded from macro '__attribute_deprecated__'
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
                                                  ^
axpy.c:95:5: warning: implicit declaration of function 'sleep' is invalid in C99 [-Wimplicit-function-declaration]
    sleep(1); 
    ^
3 warnings generated.
/usr/bin/ld: cannot find -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [makefile:8: axpyclang] Error 1

真正困扰我的是,我在 3 小时前成功执行了 makefile 并生成了一个graphml文件,但现在,我收到了新的多重警告 + 一个错误。我想知道它是否来自clang编译器(版本 10.0.0-4ubuntu1),因为收到新警告让我觉得我可能更新了编译器(但忘记了)。

请问有什么帮助吗?

标签: cmakefileclang

解决方案


  1. 您需要找到 libomp.a
  2. 将 libomp.a 所在的路径添加到ld命令行参数中-Lpath
  3. 请享用

推荐阅读