How do I run the simple.rs gimli example?

How to i run the simple.rs example?

$rustc simple.rs
error:
error[E0433]: failed to resolve: use of undeclared type or module gimli
--> simple.rs:40:10
|
40 | ) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
| ^^^^^ use of undeclared type or module gimli

error[E0433]: failed to resolve: use of undeclared type or module gimli
--> simple.rs:40:33
|
40 | ) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
| ^^^^^ use of undeclared type or module gimli

error[E0433]: failed to resolve: use of undeclared type or module gimli
--> simple.rs:41:20
|
41 | &|section| gimli::EndianSlice::new(&*section, endian);
| ^^^^^ use of undeclared type or module gimli

I have moved your post to a new help topic. Please read our post on Forum Code Formatting and Syntax Highlighting, which explains how to make your post readable.

Did you add gimli to your Cargo.toml?

I have some questions to ask before continuing on this topic:

  • What is your operating system and computer architecture ?
  • How did you install Rust toolchains?

yes i added

Ubuntu x64

It seems like you are compiling with rustc directly. You need to compile with cargo.

cargo simple.rs?

Cargo requires the files to be laid out in a certain way. You can read about it here.

In particular, cargo run --example simple should run the simple.rs example from the directory with the gimli sources, if that's what you're trying to do.

Getting this with the command you told:

error[E0465]: multiple rlib candidates for gimli found
** --> examples/simple.rs:12:13**
** |**
12 | gimli::RunTimeEndian::Little
** | ^^^^^**
** |**
note: candidate #1: /home/mbansal/gimli/target/debug/deps/libgimli-b282ebf549a656a8.rlib
** --> examples/simple.rs:12:13**
** |**
12 | gimli::RunTimeEndian::Little
** | ^^^^^**
note: candidate #2: /home/mbansal/gimli/target/debug/deps/libgimli-5c3427ce1c4fcb5d.rlib
** --> examples/simple.rs:12:13**
** |**
12 | gimli::RunTimeEndian::Little
** | ^^^^^**

error[E0463]: can't find crate for gimli
** --> examples/simple.rs:12:13**
** |**
12 | gimli::RunTimeEndian::Little
** | ^^^^^ can't find crate**

error: aborting due to 2 previous errors

For more information about this error, try rustc --explain E0463.
error: could not compile gimli.

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

Please read Forum Code Formatting and Syntax Highlighting, which I already linked once, and edit your posts accordingly.

ok

It looks like you may have ended up with two versions of gimli there. Have you changed the Cargo.toml?

yes.
added the dependency given in the guide

If you are building the gimli package itself, you don't need to add any dependencies or edit any files. Just run cargo run --example simple in an unmodifed copy of the gimli repository.

If you want to create a new package that depends on gimli, you can use cargo new to create the package, then add the dependency to Cargo.toml and paste the example code into src/main.rs.

1 Like