【问题标题】:How can I solve the "linker command failed with exit code 1" problem?如何解决“链接器命令失败,退出代码 1”问题?
【发布时间】:2021-06-07 19:24:09
【问题描述】:

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

有什么帮助吗?

【问题讨论】:

  • /usr/bin/ld: cannot find -lomp omp 找不到,请确保libomp.a(或omp.lib)确实存在于您的库搜索路径中。
  • 包含unistd.h 用于sleep 函数警告
  • ftime 的替换是 clock_gettimeGetLocalTime,具体取决于您的系统。
  • 链接器命令由于链接器推荐失败通知上面所述的原因而失败。不要自下而上地阅读错误信息。尽管在这里您似乎只阅读了底线,甚至没有向上。所有这些警告都可能是压倒性的,导致您无法看到实际的错误。解决方案很简单 - 也修复警告!
  • @ 谢谢!我摆脱了sleep 函数警告。

标签: c makefile clang


【解决方案1】:
  1. 您需要找到 libomp.a
  2. 将libomp.a所在的路径添加到ld命令行参数-Lpath
  3. 享受

【讨论】:

  • 感谢您的回答!但我还是很困惑。我找到了libomp.so。由于我不太了解ld 命令,请您提供更多信息吗?
  • @hakimo2 "use -v to see invocation" 部分将提供有用的诊断信息。它将向您展示如何调用 LD。
  • @Clifford 非常感谢!它通过添加-L/home/hakim/llvm-openmp-install/lib来工作。
  • @hakimo2 你感谢错人这个答案是 0______。
猜你喜欢
  • 2015-07-25
  • 2016-09-14
  • 1970-01-01
  • 2012-09-14
  • 1970-01-01
  • 2018-11-03
  • 2015-08-06
  • 2012-05-27
  • 1970-01-01
相关资源
最近更新 更多