immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
4k stars 240 forks source link

Failed to build c2rust after following instructions #104

Closed thedrow closed 5 years ago

thedrow commented 5 years ago

I have followed the instructions to the letter. I installed the nightly version you have specified in the README, installed all system dependencies through apt and I got this:

Compiling c2rust-transpile v0.10.0
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.0.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.1.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.10.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.11.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.12.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.13.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.14.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.15.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.2.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.3.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.4.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.5.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.6.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.7.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.8.rcgu.o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5.c2rust_transpile.2ubwvkz7-cgu.9.rcgu.o" "-o" "/tmp/cargo-installzXnIPD/release/deps/c2rust_transpile-24e500f6c8c45cc5" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/cargo-installzXnIPD/release/deps" "-L" "/tmp/cargo-installzXnIPD/release/build/curl-sys-83db6dbb04dd6cc4/out/build" "-L" "/tmp/cargo-installzXnIPD/release/build/libnghttp2-sys-29c16e4076fa313f/out/i/lib" "-L" "/home/linuxbrew/.linuxbrew/Cellar/zlib/1.2.11/lib" "-L" "/home/linuxbrew/.linuxbrew/Cellar/openssl/1.0.2r/lib" "-L" "/tmp/cargo-installzXnIPD/release/build/backtrace-sys-86d0729f58f85e0d/out" "-L" "/tmp/cargo-installzXnIPD/release/build/miniz-sys-684a2d5bbf8cd4a1/out" "-L" "/tmp/cargo-installzXnIPD/release/build/libgit2-sys-78c42f5b55e13e93/out/build" "-L" "/tmp/cargo-installzXnIPD/release/build/libssh2-sys-54b4c9f0e37e08e7/out/build" "-L" "/tmp/cargo-installzXnIPD/release/build/rlua-0a82072fd028a604/out" "-L" "/tmp/cargo-installzXnIPD/release/build/c2rust-ast-exporter-dc7b04fbd32a0abc/out/build/lib" "-L" "/tmp/cargo-installzXnIPD/release/build/c2rust-ast-exporter-dc7b04fbd32a0abc/out/build" "-L" "/usr/lib/llvm-6.0/lib" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/cargo-installzXnIPD/release/deps/libc2rust_transpile-26825231cb14a69c.rlib" "/tmp/cargo-installzXnIPD/release/deps/libpathdiff-a65c08444042156c.rlib" "/tmp/cargo-installzXnIPD/release/deps/libhandlebars-352e140b4876cb2f.rlib" "/tmp/cargo-installzXnIPD/release/deps/libwalkdir-1e2e5e51fab30f4c.rlib" "/tmp/cargo-installzXnIPD/release/deps/libsame_file-cbb4a3542eccd051.rlib" "/tmp/cargo-installzXnIPD/release/deps/libquick_error-edab00fc2efb0b4d.rlib" "/tmp/cargo-installzXnIPD/release/deps/libpest-fd3822d659839d99.rlib" "/tmp/cargo-installzXnIPD/release/deps/libucd_trie-c9733b9faddbbf6a.rlib" "/tmp/cargo-installzXnIPD/release/deps/libfailure-917a6991c5dfec97.rlib" "/tmp/cargo-installzXnIPD/release/deps/libbacktrace-1934e2ce3ad0fe5b.rlib" "/tmp/cargo-installzXnIPD/release/deps/libbacktrace_sys-6848495d0103ecda.rlib" "/tmp/cargo-installzXnIPD/release/deps/librustc_demangle-975d1ca15c57a1bc.rlib" "/tmp/cargo-installzXnIPD/release/deps/libstrum-200778788bab1bf9.rlib" "/tmp/cargo-installzXnIPD/release/deps/libfern-7ba0946fb637099a.rlib" "/tmp/cargo-installzXnIPD/release/deps/libcolored-60c86a019d50f94e.rlib" "/tmp/cargo-installzXnIPD/release/deps/liblog-d43434312aec290e.rlib" "/tmp/cargo-installzXnIPD/release/deps/libcfg_if-058a457b2cccbccb.rlib" "/tmp/cargo-installzXnIPD/release/deps/libserde_json-f6eb162ffe8c31ad.rlib" "/tmp/cargo-installzXnIPD/release/deps/libryu-95db858b5718bbb8.rlib" "/tmp/cargo-installzXnIPD/release/deps/libitoa-46efc1911e10fb8e.rlib" "/tmp/cargo-installzXnIPD/release/deps/libregex-4303a9952cb2e816.rlib" "/tmp/cargo-installzXnIPD/release/deps/libutf8_ranges-950e1c527181195f.rlib" "/tmp/cargo-installzXnIPD/release/deps/libregex_syntax-85781171c6026ad9.rlib" "/tmp/cargo-installzXnIPD/release/deps/libucd_util-0650977f211a5d30.rlib" "/tmp/cargo-installzXnIPD/release/deps/libthread_local-24ea73d06eb7a54c.rlib" "/tmp/cargo-installzXnIPD/release/deps/liblazy_static-dfb520172a0bf6f5.rlib" "/tmp/cargo-installzXnIPD/release/deps/libaho_corasick-379668c86d5bc07a.rlib" "/tmp/cargo-installzXnIPD/release/deps/libmemchr-6f4147e3dcaa0a60.rlib" "/tmp/cargo-installzXnIPD/release/deps/libitertools-30546687e66533ad.rlib" "/tmp/cargo-installzXnIPD/release/deps/libeither-471877e1a92bdfdd.rlib" "/tmp/cargo-installzXnIPD/release/deps/libc2rust_ast_exporter-e46c258c72d46f0c.rlib" "/tmp/cargo-installzXnIPD/release/deps/libserde_bytes-331d294943c442f2.rlib" "/tmp/cargo-installzXnIPD/release/deps/libc2rust_ast_builder-aafe6f3f06849c13.rlib" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lrustc-4985f416779a024f" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lfmt_macros-6d86f6bc99a5c3c9" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lrustc_fs_util-2e287c89508628d5" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-ltest-fd41e0dbf59d7c3b" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lterm-2416919cee27cd8e" "-Wl,-Bstatic" "/tmp/cargo-installzXnIPD/release/deps/libindexmap-2c181c6901acef7b.rlib" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lsyntax-63ce1c63051a8361" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lrustc_errors-37d3451656d0c6b8" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lsyntax_pos-16a3145a1a6e3022" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-larena-21bccf3f5b599f86" "-Wl,-Bstatic" "/tmp/cargo-installzXnIPD/release/deps/libserde_cbor-79cd8a166cb97873.rlib" "/tmp/cargo-installzXnIPD/release/deps/libserde-43c9a2eb45703eb8.rlib" "/tmp/cargo-installzXnIPD/release/deps/libhalf-6bdff8f163f53388.rlib" "/tmp/cargo-installzXnIPD/release/deps/libbyteorder-5888fdf999fb246e.rlib" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lrustc_target-f32c864430df4cc9" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lrustc_data_structures-7c1adc55b85b58b2" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lgraphviz-8f68c7c23876242b" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lrustc_cratesio_shim-3ba835e9cbc067b9" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lserialize-455e6a7bb53ae07a" "-Wl,-Bstatic" "/tmp/cargo-installzXnIPD/release/deps/libdtoa-33a9954742e9b92f.rlib" "/tmp/cargo-installzXnIPD/release/deps/libclap-ada618517d624d78.rlib" "/tmp/cargo-installzXnIPD/release/deps/libyaml_rust-b21750c1417be364.rlib" "/tmp/cargo-installzXnIPD/release/deps/libvec_map-bc234f88eea0e1c9.rlib" "/tmp/cargo-installzXnIPD/release/deps/libtextwrap-95f806ff545b6267.rlib" "/tmp/cargo-installzXnIPD/release/deps/libunicode_width-76bf26c8d8979ed1.rlib" "/tmp/cargo-installzXnIPD/release/deps/libstrsim-ca07be478ad9b297.rlib" "/tmp/cargo-installzXnIPD/release/deps/libbitflags-ead8e300ea6dff7e.rlib" "/tmp/cargo-installzXnIPD/release/deps/libatty-b2f8ee2d050f0235.rlib" "/tmp/cargo-installzXnIPD/release/deps/liblibc-f701350571f48eb6.rlib" "/tmp/cargo-installzXnIPD/release/deps/libansi_term-cd1ec668363a874a.rlib" "-Wl,--start-group" "-L" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lstd-6dcc0bb50fcb9989" "-Wl,--end-group" "-Wl,-Bstatic" "/home/omer/.rustup/toolchains/nightly-2019-04-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-117d1581238169da.rlib" "-Wl,-Bdynamic" "-lclangTooling" "-lclangFrontend" "-lclangASTMatchers" "-lclangParse" "-lclangSerialization" "-lclangSema" "-lclangEdit" "-lclangAnalysis" "-lclangDriver" "-lclangFormat" "-lclangToolingCore" "-lclangAST" "-lclangRewrite" "-lclangLex" "-lclangBasic" "-lLLVM" "-lstdc++" "-lutil" "-lutil" "-lutil" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
  = note: /home/linuxbrew/.linuxbrew/bin/ld: /usr/lib/llvm-6.0/lib/libLLVM.so: undefined reference to `std::thread::_State::~_State()@GLIBCXX_3.4.22'
          /home/linuxbrew/.linuxbrew/bin/ld: /usr/lib/llvm-6.0/lib/libLLVM.so: undefined reference to `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())@GLIBCXX_3.4.22'
          /home/linuxbrew/.linuxbrew/bin/ld: /usr/lib/llvm-6.0/lib/libLLVM.so: undefined reference to `typeinfo for std::thread::_State@GLIBCXX_3.4.22'
          collect2: error: ld returned 1 exit status

error: aborting due to previous error

error: failed to compile `c2rust v0.10.1`, intermediate artifacts can be found at `/tmp/cargo-installzXnIPD`

Caused by:
  Could not compile `c2rust`.

To learn more, run the command again with --verbose.

I'm using Ubuntu 18.04.2 if that helps.

rinon commented 5 years ago

It looks like it's picking up a different version of the C++ standard library than the system libLLVM.so was built against. I think you can check that by setting the environment variable RUSTFLAGS="-C link-arg=-Wl,-verbose" to print verbose info during the link step.

What's this linuxbrew thing? Could it be a newer toolchain that is incompatible with the system libLLVM.so? We've tested on Ubuntu 18.04 without the linuxbrew toolchain, so if you can get it to use the system one you should be fine.

thedrow commented 5 years ago

Linuxbrew is Homebrew for Linux.

rinon commented 5 years ago

You may need to use the libLLVM and clang from homebrew then so its version matches that of the libstdc++. https://github.com/immunant/c2rust/blob/master/docs/README-developers.md#building-with-system-llvm-libraries has some extra environment variables to control paths to LLVM and its libraries.

Alternatively, can you use the Ubuntu system compiler and linker instead of the homebrew version? That's more likely to work for you while using the system libLLVM.

thedrow commented 5 years ago

I've installed LLVM through Linuxbrew. I'm now trying LLVM_CONFIG_PATH=/home/linuxbrew/.linuxbrew/opt/llvm/bin/llvm-config cargo +nightly-2019-04-12 install c2rust.

thedrow commented 5 years ago

Yes, that worked. Should we edit the README to include linuxbrew in the installation instructions?

Maybe the build process should automatically detect if brew is installed and if brew --prefix llvm provides a result. Should we open an issue about that?

thedataking commented 5 years ago

@thedrow good point, we updated the README. Let me know if the instructions look good to you.