Bindgen chokes on 'FILE'


#1

I’m trying to use bindgen on VSTGUI’s vstgui.h file. However, upon executing bindgen, I’m spammed with the following line before bindgen panics seconds later:

C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\corecrt_wstdio.h:222:17: error: unknown type name 'FILE', err: true

There should be a way to fix this, otherwise Bindgen wouldn’t be as widely used as it is. Any help would be appreciated. I already tried --opaque-type, but to no avail.


#2

Looks like you need to include stdio.h before you can include vstgui.h

to do so your wrapper.h should look similar to this

// stdio.h contains `FILE`
#include <stdio.h>

// i have no idea if this is the right include patch adjust as needed
#include <vstgui.h>

#3

Alternative if you call bindgen like this

bindgen::builder()
    .header_contents("_stdio.h", "#include<stdio.h>\n")
    ...
            

#4

Getting the same error for a different library (RtAudio). Adding #include <stdio.h> to wrapper.h doesn’t work, I get whole host of nasty errors:

--- stdout
cargo:rustc-link-lib=RtAudio
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdlib:18:51: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdio:23:1: error: unknown type name 'namespace', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdio:23:1: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstring:9:1: error: unknown type name 'namespace', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstring:9:1: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\initializer_list:14:1: error: unknown type name 'namespace', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\initializer_list:14:1: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\malloc.h:66:48: error: unknown type name '_HEAPINFO', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:24:5: error: unknown type name 'bool', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:28:11: error: must use 'struct' tag to refer to type '__std_exception_data', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:29:11: error: must use 'struct' tag to refer to type '__std_exception_data', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:33:13: error: must use 'struct' tag to refer to type '__std_exception_data', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:40:1: error: unknown type name 'namespace', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:40:14: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:227:15: error: unknown type name 'bool', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:227:20: error: expected identifier or '(', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:228:15: error: unknown type name 'bool', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:228:20: error: expected identifier or '(', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:235:1: error: unknown type name 'namespace', err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true

--- stderr
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdlib:18:51: error: expected function body after function declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdio:23:1: error: unknown type name 'namespace'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstdio:23:1: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstring:9:1: error: unknown type name 'namespace'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\cstring:9:1: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\initializer_list:14:1: error: unknown type name 'namespace'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\initializer_list:14:1: error: expected ';' after top level declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\malloc.h:66:48: error: unknown type name '_HEAPINFO'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:24:5: error: unknown type name 'bool'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:28:11: error: must use 'struct' tag to refer to type '__
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:29:11: error: must use 'struct' tag to refer to type '__
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:33:13: error: must use 'struct' tag to refer to type '__
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:40:1: error: unknown type name 'namespace'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime_exception.h:40:14: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:227:15: error: unknown type name 'bool'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:227:20: error: expected identifier or '('
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:228:15: error: unknown type name 'bool'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:228:20: error: expected identifier or '('
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\exception:235:1: error: unknown type name 'namespace'
fatal error: too many errors emitted, stopping now [-ferror-limit=]

#5

Problem is due to the library’s reliance on exceptions. Fixed it by using an available C API.