immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.91k stars 229 forks source link

“fatal error: 'stdarg.h' file not found” #941

Open LenaWil opened 1 year ago

LenaWil commented 1 year ago

I am trying to compile Iodine on macOS, but I get the following error when I try:

warning: Skipping existing file /Users/lena/Documents/Knights/dns/iodine/src/tun.rs
warning: Skipping existing file /Users/lena/Documents/Knights/dns/iodine/src/dns.rs
warning: Skipping existing file /Users/lena/Documents/Knights/dns/iodine/src/read.rs
In file included from encoding.c:19:
./common.h:35:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
         ^~~~~~~~~~
1 error generated.
Error while processing /Users/lena/Documents/Knights/dns/iodine/src/encoding.c.
warning: Missing child 140207781617872 of node AstNode { tag: TagImplicitCastExpr, children: [Some(140207781617872)], loc: SrcSpan { fileid: 77, begin_line: 39, begin_column: 7, end_line: 39, end_column: 16 }, type_id: Some(140207781435984), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [Text("LValueToRValue")] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /Users/lena/Documents/Knights/dns/iodine/src/encoding.c:39:7
 [-Wclang-ast]
warning: Missing child 140207798932416 of node AstNode { tag: TagImplicitCastExpr, children: [Some(140207798932416)], loc: SrcSpan { fileid: 77, begin_line: 32, begin_column: 7, end_line: 32, end_column: 16 }, type_id: Some(140207781435984), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [Text("LValueToRValue")] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /Users/lena/Documents/Knights/dns/iodine/src/encoding.c:32:7
 [-Wclang-ast]
warning: Missing child 140207807182168 of node AstNode { tag: TagImplicitCastExpr, children: [Some(140207807182168)], loc: SrcSpan { fileid: 77, begin_line: 60, begin_column: 7, end_line: 60, end_column: 12 }, type_id: Some(140207781435984), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [Text("LValueToRValue")] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /Users/lena/Documents/Knights/dns/iodine/src/encoding.c:60:7
 [-Wclang-ast]
thread 'main' panicked at 'Type conversion not implemented for TagTypeUnknown expecting 3', c2rust-transpile/src/c_ast/conversion.rs:818:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I think I am running https://github.com/immunant/c2rust/commit/d1e05f3203efa29d1277eead56a33d93d549ac0b, since I needed #892 I used the Git version.

My compile_commands.json looks like this:

[
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "tun.c",
   "-o",
   "tun.o"
  ],
  "file": "tun.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "dns.c",
   "-o",
   "dns.o"
  ],
  "file": "dns.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "read.c",
   "-o",
   "read.o"
  ],
  "file": "read.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "encoding.c",
   "-o",
   "encoding.o"
  ],
  "file": "encoding.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "login.c",
   "-o",
   "login.o"
  ],
  "file": "login.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "base32.c",
   "-o",
   "base32.o"
  ],
  "file": "base32.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "base64.c",
   "-o",
   "base64.o"
  ],
  "file": "base64.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "base64u.c",
   "-o",
   "base64u.o"
  ],
  "file": "base64u.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "base128.c",
   "-o",
   "base128.o"
  ],
  "file": "base128.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "md5.c",
   "-o",
   "md5.o"
  ],
  "file": "md5.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "common.c",
   "-o",
   "common.o"
  ],
  "file": "common.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "iodine.c",
   "-o",
   "iodine.o"
  ],
  "file": "iodine.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "client.c",
   "-o",
   "client.o"
  ],
  "file": "client.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "util.c",
   "-o",
   "util.o"
  ],
  "file": "util.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "iodined.c",
   "-o",
   "iodined.o"
  ],
  "file": "iodined.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "user.c",
   "-o",
   "user.o"
  ],
  "file": "user.c"
 },
 {
  "directory": "/Users/lena/Documents/Knights/dns/iodine/src",
  "arguments": [
   "cc",
   "-std=c99",
   "-c",
   "-g",
   "-Wall",
   "-DDARWIN",
   "-pedantic",
   "-D__APPLE_USE_RFC_3542",
   "-DGITREVISION=\"b82bc77\"",
   "-Wstrict-prototypes",
   "-Wtype-limits",
   "-Wmissing-declarations",
   "-Wmissing-prototypes",
   "fw_query.c",
   "-o",
   "fw_query.o"
  ],
  "file": "fw_query.c"
 }
]
lu-zero commented 1 year ago

passing

-I `llvm-config --includedir`

should fix it (where the llvm-config is the one you used to build c2rust)

dears1rr commented 7 months ago

I've had a comparable error for stddef.h; using clang I had to add: -I /usr/lib/clang/<your-version>/include/. If you're using gcc add -I /usr/lib/gcc/x86_64-pc-linux-gnu/<your-version>/include if you have this error too.