Cdk-rs 0.6.* can't run tests

It seems like after decoupling of ic0 crate from cdk-rs crate something went wrong.

I still can use cargo build for my projects, but not cargo test:

error: linking with `cc` failed: exit status: 1
  = note: "cc" "-m64" "/tmp/rustcAgGAPp/symbols.o" "/home/alexander/IdeaProjects/ic-stable-memory/target/debug/deps/ic_stable_memory-af206a0cde78a87c.10t3jbqh57ut461e.rcgu.o" "/home/alexander/IdeaProjects/ic-stable-memory/target/debug/deps/ic_stable_memory-af206a0cde78a87c.11543p07sull3p31.rcgu.o" "/home/alexander/IdeaProjects/ic-stable-memory/target/debug/deps/ic_stable_memory-af206a0cde78a87c.130geevnzwplkrxq.rcgu.o" "/home/alexander/IdeaProjects/ic-stable-memory/target/debug/deps/ic_stable_memory-...
  = note: /usr/bin/ld: /home/alexander/IdeaProjects/ic-stable-memory/target/debug/deps/libic_cdk-2146a3f3358a2c93.rlib(ic_cdk-2146a3f3358a2c93.ic_cdk.5f9620fa-cgu.8.rcgu.o): in function `ic_cdk::api::trap':
          /home/alexander/.cargo/registry/src/ undefined reference to `trap'
          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

How to fix?

1 Like

Would appreciate some inputs on this because this is a blocker for using ic_cdk v0.6 onwards and candid v0.8 onwards in a project that relies on ic-stable-memory.

@chenyan @lwshang Tagging you since you are the owners of the respective crates

1 Like

We haven’t had a common way to run cargo test on rust canisters.
I speculate that your cargo test is targeting your host OS instead of wasm32. So the linker complained about symbol not found.

It used to work because ic-cdk defined virtual API endpoints for non-wasm32 targets which don’t link to extern functions, as can be seen in the source code before ic0 split.

I will soon add those virtual endpoints to ic0.

1 Like

ic0 v0.18.6 is out with fix for this issue.

Bump ic0 in Cargo.lock should solve your issue now.

1 Like

Now everything works as expected.
Thank you very much!