【问题标题】:LLVM cannot find clang binaryLLVM 找不到 clang 二进制文件
【发布时间】:2015-02-14 04:30:24
【问题描述】:

我刚刚使用 compiler-rt 构建并安装了 LLVM Clang 3.5.0。 clang 二进制似乎可以工作,但无法构建简单的测试程序:

$ cat hello.c 
#include <stdio.h>
int main(int argc, char **argv) {
    printf("Hello World\n");
    return 0;
}

使用 error: unable to execute command: Executable "" doesn't exist! 构建它很糟糕

$ clang hello.c -o hello
error: unable to execute command: Executable "" doesn't exist!

可执行文件“”?有趣...

调试进一步发现clang试图调用自己构建.o目标文件,然后ld链接它,但显然不知道自己存在于哪里。

$ clang -### hello.c -o hello
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-alpine-linux-musl
Thread model: posix
 "" "-cc1" "-triple" "x86_64-alpine-linux-musl" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-target-linker-version" "2.24" "-dwarf-column-info" "-resource-dir" "../lib/clang/3.5.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "../lib/clang/3.5.0/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdebug-compilation-dir" "/" "-ferror-limit" "19" "-fmessage-length" "158" "-mstackrealign" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-o" "/tmp/hello-37746e.o" "-x" "c" "hello.c"
 "/usr/bin/ld" "-z" "relro" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib/ld-musl-x86_64.so.1" "-o" "hello" "/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/../../../crt1.o" "/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/../../../crti.o" "/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/crtbegin.o" "-L/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3" "-L/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/../../../../x86_64-alpine-linux-musl/lib" "-L/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/../../.." "-L/../lib" "-L/lib" "-L/usr/lib" "/tmp/hello-37746e.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/crtend.o" "/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/4.8.3/../../../crtn.o"

当我运行第一行将/usr/bin/clang 作为第一项时,它构建得很好:

$ /usr/bin/clang "-cc1" "-triple" "x86_64-alpine-linux-musl" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-target-linker-version" "2.24" "-dwarf-column-info" "-resource-dir" "../lib/clang/3.5.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "../lib/clang/3.5.0/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdebug-compilation-dir" "/" "-ferror-limit" "19" "-fmessage-length" "158" "-mstackrealign" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-o" "/tmp/hello-4f64bb.o" "-x" "c" "hello.c"
$ 

并且关注/usr/bin/ld 能够很好地链接它导致:

$ ./hello
Hello World

任何建议我在配置/构建期间搞砸了什么?

【问题讨论】:

  • 那么你是如何获得这个clang版本的呢?你在什么操作系统上? which clang 结果是什么?
  • 我自己搭建的。我在 Alpine Linux 3.1 上。 which clang 报告/usr/bin/clang

标签: clang llvm llvm-clang


【解决方案1】:

clang 源码分析表明,Linux 上的“clang”程序使用/proc/self/exe 来查找其二进制文件的真实路径。我在没有安装 /proc 的情况下在 chroot 中运行,因此它失败了。

mount -t proc proc /proc

解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 2015-10-02
    • 2020-05-10
    • 2019-07-05
    • 2020-03-22
    • 1970-01-01
    • 2013-03-24
    相关资源
    最近更新 更多