如何解决“链接器命令失败,退出代码为 1”的问题?

时间:2021-06-07 19:24:09

标签: c makefile clang

我正在尝试使用 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),因为收到新警告让我觉得我可能更新了编译器(但忘记了)。

有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

  1. 您需要找到 libomp.a
  2. 将 libomp.a 所在的路径添加到 ld 命令行参数 -Lpath
  3. 享受
相关问题