djg / verilated-rs

Verilator Porcelain
Apache License 2.0
36 stars 14 forks source link

Example build fails to link #8

Closed simeonmiteff closed 2 years ago

simeonmiteff commented 2 years ago

Hi @djg

I'm using rustc 1.55 and verilator 4.212 on Linux and I encountered a linking issue:

simeon@feijoa:/tmp/verilated-rs$ cargo run -p example
warning: unused import: `std::ffi::c_void`
 --> verilated/src/api.rs:9:9
  |
9 |     use std::ffi::c_void;
  |         ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `verilated` (lib) generated 1 warning
   Compiling example v0.0.0 (/tmp/verilated-rs/example)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.18b79lvnwpn9r1zy.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.21stysm9a1xuc8i8.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.280ae6a8cs4id9l5.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.2jtgxy57p59wek4p.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.2nhdlorttu21link.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.2x5s3cunlu2620wp.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.2xvxvchbvupuz31y.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.2yn42j4l8khsd8uq.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.38m2j19045s27m66.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.3a3b7x1hhvq40klp.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.3hmmeklggrh01150.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.3ir22fkumruqu6ol.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.3m7eztqerrmg8cb1.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.48te9rk7v5t4n36s.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4gm1mnnh3op5u2bu.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4gvvt7r4bykf9l7u.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4kk66rd7rdso56i9.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4si4qdcw01ymjz7e.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4tach42rqt5ga65m.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.523e162ckamd8mqd.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.54uj4gjk1bvbal2m.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.7tzwz1ubbt1h04q.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.8hkikejsf0av0f4.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.uhlyej8pn4skmdg.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.y9xzg7vr3d4uga1.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.zjbziw0ga99m694.rcgu.o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f.4yfn2b2rz8vwaygd.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/verilated-rs/target/debug/deps" "-L" "/tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out" "-L" "/tmp/verilated-rs/target/debug/build/verilated-c6ea5e8f28d0adcf/out" "-L" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-lVtop__ALL" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lstdc++" "-Wl,-Bstatic" "/tmp/verilated-rs/target/debug/deps/libverilated-1cdf6aa9d5e0e34b.rlib" "-Wl,--start-group" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-008055cc7d873802.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-06f01ac2578bda94.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f9a3c3274a1835e0.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-d4cbb754ee9f4daa.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-95c14e1c1e3ebcc4.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-d489f0ca872880cc.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-75f07df0b18fea39.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-0c35b278736219a2.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e530649c9a06e3c6.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-6b148909d375a785.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cd15fa647f4775d1.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-74be3a703f788ba2.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8f2c5b445c28b2e3.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-8480e85e0be96197.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ac23a75f6f42004e.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-557ba8776e04d182.rlib" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4beb03d03503c439.rlib" "-Wl,--end-group" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-dd7db1bec6909f24.rlib" "-Wl,-Bdynamic" "-lstdc++" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/simeon/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/tmp/verilated-rs/target/debug/deps/example-9a2255ec8b8ae24f" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a(Vtop.o): in function `Vtop::_eval_initial_loop(Vtop__Syms*)':
          /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/Vtop.cpp:45: undefined reference to `Vtop::_eval_initial(Vtop__Syms*)'
          /usr/bin/ld: /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/Vtop.cpp:51: undefined reference to `Vtop::_eval_settle(Vtop__Syms*)'
          /usr/bin/ld: /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a(top.o): in function `top_new':
          /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/top.cpp:7: undefined reference to `Vtop::Vtop(char const*)'
          /usr/bin/ld: /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a(top.o): in function `top_delete':
          /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/top.cpp:15: undefined reference to `Vtop::~Vtop()'
          /usr/bin/ld: /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a(top.o): in function `top_final':
          /tmp/verilated-rs/target/debug/build/example-b9b2d66896358201/out/top.cpp:31: undefined reference to `Vtop::final()'
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `example` due to previous error

I'm still trying to wrap my head around how the build is supposed to work, but figure maybe you already know why those symbols would be missing?

Regards, Simeon.

simeonmiteff commented 2 years ago

FYI, ./target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a is getting built and contains the Vtop class.

The linking step that fails includes among the many arguments:

This seems OK to me :man_shrugging:...

simeonmiteff commented 2 years ago

Oh no, I misread the output of nm, they are indeed U (for undefined):

$ nm -g ./target/debug/build/example-b9b2d66896358201/out/libVtop__ALL.a | c++filt | grep 'Vtop::_eval_initial('
                 U Vtop::_eval_initial(Vtop__Syms*)
simeonmiteff commented 2 years ago

Damn, sorry for the noise.

I think I had some old object files from a previous failed build with an older version of verilator. The linking issue went away to be replaced by a different issue. I'll close this for now and open another issue if I don't manage to work it out by myself.