WasmEdge icon indicating copy to clipboard operation
WasmEdge copied to clipboard

bug: link to static lib 0.14.0 encounters undefined reference to `fmtt::v10::***`

Open CaptainVincent opened this issue 1 year ago • 6 comments

Summary

As the title, the new released version of the static library cannot be linked.

Current State

The symbols related to fmt are undefined.

Expected State

Without compile error.

Reproduction steps

  1. When releasing the current Rust SDK, we forgot to update the archives version and checksum. You could use mine for test https://github.com/CaptainVincent/wasmedge-rust-sdk/tree/update-archives
  2. Create a new cargo proj Cargo.toml
[package]
name = "test_wasmedge_static_link"
version = "0.1.0"
edition = "2021"

[dependencies]
wasmedge-sdk = { git = "https://github.com/CaptainVincent/wasmedge-rust-sdk.git", branch = "update-archives" }

[features]
default = ["standalone", "static"]
standalone = ["wasmedge-sdk/standalone"]
static = ["wasmedge-sdk/static"]
wasi_nn = ["wasmedge-sdk/wasi_nn"]

src/main.rs

use wasmedge_sdk::wasi::WasiModule;

fn main() {
    let mut _wasi = WasiModule::create(None, None, Some(vec!["/:/"])).unwrap();
    println!("Hello, world!");
}
  1. run cargo build

Screenshots

None

Any logs you want to share for showing the specific issue

err.log

Components

Rust SDK

WasmEdge Version or Commit you used

0.14.0

Operating system information

Ubuntu 22.04.4 LTS

Hardware Architecture

x86_64

Compiler flags and options

Appendix:

I tried to verify this issue in the pure WasmEdge compile flow using the following flags.

cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_BUILD_SHARED_LIB=Off -DWASMEDGE_BUILD_STATIC_LIB=On -DWASMEDGE_LINK_TOOLS_STATIC=On -DWASMEDGE_BUILD_PLUGINS=Off -DWASMEDGE_BUILD_AOT_RUNTIME=OFF

But when I tried to compile the static library and link it to the tool, I encountered the following error, which prevented me from verifying:

ninja: error: '/usr/lib/llvm-11/lib/libPolly.a', needed by 'tools/wasmedge/wasmedgec', missing and no known rule to make it

CaptainVincent avatar Jun 10 '24 06:06 CaptainVincent

@q82419 We have to link the fmt library statically. The runwasi project requires this statical build.

@CaptainVincent The environment must provide the libPolly.a dependency if the AOT is needed in this asset. However, you can use WASMEDGE_USE_LLVM=OFF to turn it off as a workaround. The runwasi project will not need the AOT feature due to the execution pipeline.

hydai avatar Jun 10 '24 06:06 hydai

Quick update: Try linking static libfmt.a in SDK build.rs but still get error, still trying to find possible causes.

  = note: /usr/bin/ld: /home/vincent/workspace/_docker/_ctr/test_wasmedge_static_link/target/debug/deps/libwasmedge_sys-bb01cfa1ba8bae59.rlib(section.cpp.o): in function `WasmEdge::Loader::Loader::loadSection(WasmEdge::AST::Component::CoreTypeSection&)':
          section.cpp:(.text+0x3952): undefined reference to `WasmEdge::Loader::Loader::loadType(std::variant<WasmEdge::AST::FunctionType, WasmEdge::AST::Component::ModuleType>&)'
          /usr/bin/ld: /home/vincent/workspace/_docker/_ctr/test_wasmedge_static_link/target/debug/deps/libwasmedge_sys-bb01cfa1ba8bae59.rlib(section.cpp.o): in function `WasmEdge::Loader::Loader::loadSection(WasmEdge::AST::Component::TypeSection&)':
          section.cpp:(.text+0x3bb2): undefined reference to `WasmEdge::Loader::Loader::loadType(std::variant<std::variant<WasmEdge::AST::Component::PrimValType, WasmEdge::AST::Component::Record, WasmEdge::AST::Component::VariantTy, WasmEdge::AST::Component::List, WasmEdge::AST::Component::Tuple, WasmEdge::AST::Component::Flags, WasmEdge::AST::Component::Enum, WasmEdge::AST::Component::Option, WasmEdge::AST::Component::Result, WasmEdge::AST::Component::Own, WasmEdge::AST::Component::Borrow>, WasmEdge::AST::Component::FuncType, WasmEdge::AST::Component::ComponentType, WasmEdge::AST::Component::InstanceType>&)'
          /usr/bin/ld: /home/vincent/workspace/_docker/_ctr/test_wasmedge_static_link/target/debug/deps/libwasmedge_sys-bb01cfa1ba8bae59.rlib(import_export.cpp.o): in function `WasmEdge::Loader::Loader::loadImport(WasmEdge::AST::Component::Import&)':
          import_export.cpp:(.text+0x18): undefined reference to `WasmEdge::Loader::Loader::loadImportName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
          /usr/bin/ld: import_export.cpp:(.text+0x33): undefined reference to `WasmEdge::Loader::Loader::loadExternDesc(std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)'
          /usr/bin/ld: /home/vincent/workspace/_docker/_ctr/test_wasmedge_static_link/target/debug/deps/libwasmedge_sys-bb01cfa1ba8bae59.rlib(import_export.cpp.o): in function `WasmEdge::Loader::Loader::loadExport(WasmEdge::AST::Component::Export&)':
          import_export.cpp:(.text+0xcd): undefined reference to `WasmEdge::Loader::Loader::loadExportName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
          /usr/bin/ld: /home/vincent/workspace/_docker/_ctr/test_wasmedge_static_link/target/debug/deps/libwasmedge_sys-bb01cfa1ba8bae59.rlib(import_export.cpp.o): in function `std::_Function_handler<cxx20::expected<void, WasmEdge::ErrCode> (std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&), WasmEdge::Loader::Loader::loadExport(WasmEdge::AST::Component::Export&)::$_0>::_M_invoke(std::_Any_data const&, std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)':
          import_export.cpp:(.text+0x35d): undefined reference to `WasmEdge::Loader::Loader::loadExternDesc(std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)'
          collect2: error: ld returned 1 exit status

CaptainVincent avatar Jun 24 '24 06:06 CaptainVincent

Hi @CaptainVincent Is this fixed?

hydai avatar Jul 13 '24 22:07 hydai

Using the latest released build (0.14.0) and statically linking against libfmt, I see the same result as @CaptainVincent

  = note: /usr/bin/ld: /home/jprendes/Projects/runwasi2/target/x86_64-unknown-linux-gnu/debug/deps/libwasmedge_sys-33d272e10155aeef.rlib(section.cpp.o): in function `WasmEdge::Loader::Loader::loadSection(WasmEdge::AST::Component::CoreTypeSection&)':
          section.cpp:(.text+0x3952): undefined reference to `WasmEdge::Loader::Loader::loadType(std::variant<WasmEdge::AST::FunctionType, WasmEdge::AST::Component::ModuleType>&)'
          /usr/bin/ld: /home/jprendes/Projects/runwasi2/target/x86_64-unknown-linux-gnu/debug/deps/libwasmedge_sys-33d272e10155aeef.rlib(section.cpp.o): in function `WasmEdge::Loader::Loader::loadSection(WasmEdge::AST::Component::TypeSection&)':
          section.cpp:(.text+0x3bb2): undefined reference to `WasmEdge::Loader::Loader::loadType(std::variant<std::variant<WasmEdge::AST::Component::PrimValType, WasmEdge::AST::Component::Record, WasmEdge::AST::Component::VariantTy, WasmEdge::AST::Component::List, WasmEdge::AST::Component::Tuple, WasmEdge::AST::Component::Flags, WasmEdge::AST::Component::Enum, WasmEdge::AST::Component::Option, WasmEdge::AST::Component::Result, WasmEdge::AST::Component::Own, WasmEdge::AST::Component::Borrow>, WasmEdge::AST::Component::FuncType, WasmEdge::AST::Component::ComponentType, WasmEdge::AST::Component::InstanceType>&)'
          /usr/bin/ld: /home/jprendes/Projects/runwasi2/target/x86_64-unknown-linux-gnu/debug/deps/libwasmedge_sys-33d272e10155aeef.rlib(import_export.cpp.o): in function `WasmEdge::Loader::Loader::loadImport(WasmEdge::AST::Component::Import&)':
          import_export.cpp:(.text+0x18): undefined reference to `WasmEdge::Loader::Loader::loadImportName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
          /usr/bin/ld: import_export.cpp:(.text+0x33): undefined reference to `WasmEdge::Loader::Loader::loadExternDesc(std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)'
          /usr/bin/ld: /home/jprendes/Projects/runwasi2/target/x86_64-unknown-linux-gnu/debug/deps/libwasmedge_sys-33d272e10155aeef.rlib(import_export.cpp.o): in function `WasmEdge::Loader::Loader::loadExport(WasmEdge::AST::Component::Export&)':
          import_export.cpp:(.text+0xcd): undefined reference to `WasmEdge::Loader::Loader::loadExportName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
          /usr/bin/ld: /home/jprendes/Projects/runwasi2/target/x86_64-unknown-linux-gnu/debug/deps/libwasmedge_sys-33d272e10155aeef.rlib(import_export.cpp.o): in function `std::_Function_handler<cxx20::expected<void, WasmEdge::ErrCode> (std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&), WasmEdge::Loader::Loader::loadExport(WasmEdge::AST::Component::Export&)::$_0>::_M_invoke(std::_Any_data const&, std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)':
          import_export.cpp:(.text+0x35d): undefined reference to `WasmEdge::Loader::Loader::loadExternDesc(std::variant<WasmEdge::AST::Component::DescTypeIndex, std::optional<unsigned int>, std::variant<WasmEdge::AST::Component::PrimValType, unsigned int> >&)'
          collect2: error: ld returned 1 exit status
          
  = note: 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#rustc-link-lib)

jprendes avatar Jul 22 '24 11:07 jprendes

There's still an issue with missing symbols for WasmEdge::Loader. Has that also been fixed?

jprendes avatar Jul 29 '24 09:07 jprendes

~~Yes~~ Not yet, wait for the next WasmEdge 0.14.1 release, which will include commit a498fb1.

CaptainVincent avatar Jul 29 '24 09:07 CaptainVincent

@CaptainVincent It looks like WasmEdge 0.14.1 was released in Sep: https://github.com/WasmEdge/WasmEdge/releases/tag/0.14.1

Would you say this issue is resolved? If so, can you please take a look at this one from runwasi: https://github.com/containerd/runwasi/pull/607? 🙏🙏

Mossaka avatar Nov 17 '24 06:11 Mossaka

Got the message, I’ll pin our colleague responsible for releasing the WasmEdge SDK to check when they can help release the Rust crate that includes lib version 0.14.1.

CaptainVincent avatar Nov 19 '24 16:11 CaptainVincent