Skip to content

Can't compile c2rust-generated program using rustc #661

Closed
@NobinPegasus

Description

@NobinPegasus

Here's my C code:

#include <stdio.h>
void main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   
}

Here's the rust code generated by c2rust:

#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case,
         non_upper_case_globals, unused_assignments, unused_mut)]
#![register_tool(c2rust)]
#![feature(main, register_tool)]
extern "C" {
    #[no_mangle]
    fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
}
unsafe fn main_0() {
    // printf() displays the string inside quotation
    printf(b"Hello, World!\x00" as *const u8 as *const libc::c_char);
}
#[main]
pub fn main() { unsafe { main_0() } ::std::process::exit(0i32); }

I'm unable to compile the generated code using rustc.

When tried to compile it gives the following error message:

┌──(pegasus㉿pegasus)-[~/Documents/Rust_testing]
└─$ rustc output.rs -o test2
error[E0557]: feature has been removed
 --> output.rs:4:12
  |
4 | #![feature(main, register_tool)]
  |            ^^^^ feature has been removed

error: cannot find attribute `main` in this scope
  --> output.rs:13:3
   |
13 | #[main]
   |   ^^^^
   |
   = note: `main` is in scope, but it is a function, not an attribute

error[E0433]: failed to resolve: use of undeclared crate or module `libc`
 --> output.rs:7:21
  |
7 | fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
  |                     ^^^^ use of undeclared crate or module `libc`

error[E0433]: failed to resolve: use of undeclared crate or module `libc`
 --> output.rs:7:46
  |
7 | fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
  |                                              ^^^^ use of undeclared crate or module `libc`

error[E0433]: failed to resolve: use of undeclared crate or module `libc`
  --> output.rs:11:52
   |
11 | printf(b"Hello, World!\x00" as *const u8 as *const libc::c_char);
   |                                                    ^^^^ use of undeclared crate or module `libc`

warning: `#[no_mangle]` has no effect on a foreign function
 --> output.rs:6:1
  |
6 | #[no_mangle]
  | ^^^^^^^^^^^^ help: remove this attribute
7 | fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
  | --------------------------------------------------------- foreign function
  |
  = note: `#[warn(unused_attributes)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: symbol names in extern blocks are not mangled

error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0433, E0557.
For more information about an error, try `rustc --explain E0433`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions