Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `__ink_generate_metadata' #909

Closed
forgetso opened this issue Jan 17, 2023 · 11 comments · Fixed by #977
Closed

undefined reference to `__ink_generate_metadata' #909

forgetso opened this issue Jan 17, 2023 · 11 comments · Fixed by #977
Assignees
Labels
question Further information is requested

Comments

@forgetso
Copy link
Contributor

forgetso commented Jan 17, 2023

Hi,

I'm unable to generate the metadata when compiling a contract that has a reference to a second contract using cargo-contract-contract 2.0.0-rc-3c084d2-x86_64-unknown-linux-gnu.

error: linking with `cc` failed: exit status: 1

...

  = note: /usr/bin/ld: /home/user/dev/prosopo/dapp-example/contracts/target/ink/release/deps/metadata_gen-fb8a1845a23ecd3e.metadata_gen.4b911e9c-cgu.12.rcgu.o: in function `metadata_gen::main':
          metadata_gen.4b911e9c-cgu.12:(.text._ZN12metadata_gen4main17hecbff74e26d81eb9E+0x11): undefined reference to `__ink_generate_metadata'

          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#cargorustc-link-libkindname)

error: could not compile `metadata-gen` due to previous error
ERROR: `"/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo" "run" "--package" "metadata-gen" "--manifest-path=/tmp/cargo-contract_dsvUuc/Cargo.toml" "--target-dir=/home/user/dev/prosopo/dapp-example/contracts/target/ink" "--release" ""` failed with exit code: Some(101)


The contract tomls are here and here. The second one references the first one in its toml. The first contract compiles ok.

rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/user/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-2022-03-14-x86_64-unknown-linux-gnu
nightly-2022-06-20-x86_64-unknown-linux-gnu
nightly-2022-06-30-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.68.0-nightly (4781233a7 2023-01-16)

I've now tried this with both a local copy of cargo-contract and when installed using cargo install cargo-contract --version 2.0.0-rc.

@forgetso
Copy link
Contributor Author

It seems like linking this function is not working.

extern "Rust" {
    // Note: The ink! metadata codegen generates an implementation for this function,
    // which is what we end up linking to here.

    fn __ink_generate_metadata() -> ink::metadata::InkProject;
}

@forgetso
Copy link
Contributor Author

forgetso commented Jan 18, 2023

Seems related to #199 (comment).

I have features = ["ink-as-dependency"] } in the contract thats calling the other contract as per the delegator example.

@HCastano
Copy link
Contributor

HCastano commented Feb 9, 2023

@forgetso we recently merged some changes around contracts depending on other contracts. See #927.

Can you try again with the latest ink! and cargo-contract releases?

@HCastano HCastano added the question Further information is requested label Feb 9, 2023
@forgetso
Copy link
Contributor Author

forgetso commented Feb 14, 2023

Hi @HCastano, I've now tried with the following versions and I'm hitting the same error:

In both parent and child contract, using v4.0.0-rc

ink = { git = "https://github.com/paritytech/ink", rev="59bbd36c1161370697882532c21ee1833e729f13", default-features = false }

With

cargo contract --version
cargo-contract-contract 2.0.0-rc.1-0a98d16-x86_64-unknown-linux-gnu

Returns

          metadata_gen.a505040f-cgu.13:(.text._ZN12metadata_gen4main17hef77d893018b6d58E+0x11): undefined reference to `__ink_generate_metadata'
          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#cargorustc-link-libkindname)

error: could not compile `metadata-gen` due to previous error
ERROR: `"/home/user/.rustup/toolchains/1.67.0-x86_64-unknown-linux-gnu/bin/cargo" "run" "--package" "metadata-gen" "--manifest-path=/tmp/cargo-contract_9u8kw6/Cargo.toml" "--target-dir=/home/user/dev/prosopo/dapp-example/contracts/target/ink" "--release" "" "--verbose"` failed with exit code: Some(101)

@forgetso
Copy link
Contributor Author

forgetso commented Feb 15, 2023

Correction, I was using this commit for ink: use-ink/ink@50b32f4 which is the actual v4 release candidate.

@HCastano
Copy link
Contributor

@forgetso I managed to reproduce this, but I still need to dig in further to see what's wrong.

Can you do a few things in the meantime:

  • Update to ink! 4.0
    • This will involve cleaning up a few things from your Cargo.toml file, see the template from cargo-contract
  • Make sure the branch references are still up to date, there are some dead links in your descriptions and Cargo.toml's (e.g no more inkv4 branch in the protocol repo)
  • Create a minimal reproducer, ideally in a single repo (this would be the most helpful thing)

@forgetso
Copy link
Contributor Author

Apologies, the inkv4 branch is merged into develop and we auto purge old branches. I'll create a reproducible example and upgrade ink.

@forgetso
Copy link
Contributor Author

forgetso commented Feb 16, 2023

Here is a reproducible example using inkv4 with instructions.

https://github.com/prosopo/ink_generate_metadata

It looks like the cargo contract templates are still using the ink release candidate btw.

@HCastano
Copy link
Contributor

It looks like the cargo contract templates are still using the ink release candidate btw.

Haha, yeah I noticed yesterday #971 😅

@ascjones
Copy link
Collaborator

Should be fixed with #977.

For an immediate fix try adding default = ["std"] to the [features] section of your Cargo.toml

@forgetso
Copy link
Contributor Author

Thanks guys, very much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants