Rust-bindgen: Weird errors when running under windows

Created on 22 Feb 2018  路  6Comments  路  Source: rust-lang/rust-bindgen

Input C/C++ Header

https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/core_c.h

Bindgen Invocation

$ bindgen opencv/include/opencv2/core/core_c.h -o core.rs -- "-Iopencv/include"

Actual Results

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vadefs.h:28:33: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:81:1: error: expected identifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:81:20: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:180:29: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:283:51: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:284:67: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:288:8: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:296:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\limits.h:13:1: error: expected function body after function declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:12:1: error: expected identifier
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:12:20: error: expected ';' after top level declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:262:16: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:1982:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_malloc.h:13:1: error: expected function body after function declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_malloc.h:228:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:16:1: error: expected function body after function declarator
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:31:32: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:39:33: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:69:33: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vadefs.h:28:33: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:81:1: error: expected identifier, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:81:20: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:180:29: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:283:51: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:284:67: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:288:8: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:296:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\limits.h:13:1: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:12:1: error: expected identifier, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:12:20: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:262:16: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt.h:1982:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_malloc.h:13:1: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_malloc.h:228:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:16:1: error: expected function body after function declarator, err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:31:32: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction', err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:39:33: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction', err: true
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\corecrt_search.h:69:33: error: unknown type name '_CoreCrtSecureSearchSortCompareFunction', err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'Unable to generate bindings: ()', src\libcore\result.rs:916:5
stack backtrace:
   0: std::sys::windows::backtrace::unwind_backtrace
             at src\libstd\sys\windows\backtrace/mod.rs:65
   1: std::sys_common::backtrace::print
             at src\libstd\sys_common/backtrace.rs:68
             at src\libstd\sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at src\libstd/panicking.rs:381
   3: std::panicking::default_hook
             at src\libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at src\libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at src\libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at src\libstd/panicking.rs:522
   7: rust_begin_unwind
             at src\libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at src\libcore/panicking.rs:71
   9: core::result::unwrap_failed
  10: std::panicking::try::do_call
  11: _rust_maybe_catch_panic
             at src\libpanic_unwind/lib.rs:101
  12: bindgen::main
  13: std::rt::lang_start::{{closure}}
  14: std::panicking::try::do_call
             at src\libstd/rt.rs:59
             at src\libstd/panicking.rs:480
  15: _rust_maybe_catch_panic
             at src\libpanic_unwind/lib.rs:101
  16: std::panicking::try
             at src\libstd/panicking.rs:459
  17: std::rt::lang_start_internal
             at src\libstd/panic.rs:365
             at src\libstd/rt.rs:58
  18: main
  19: _tmainCRTStartup
  20: mainCRTStartup
  21: unit_addrs_search

Expected Results

Successful generation


msbuild 15.5.180.51428
clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-pc-windows-msvc
Thread model: posix

clang-check shows warnings only:

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "C:/Users/SOLO/Documents/Github/ocv/mingw/install/opencv/include/opencv2/core/core_c.h"
No compilation database found in C:\Users\SOLO\Documents\Github\ocv\mingw\install\opencv\include\opencv2\core or any parent directory
json-compilation-database: Error while opening JSON database: no such file or directory
Running without flags.
In file included from C:\Users\SOLO\Documents\Github\ocv\mingw\install\opencv\include\opencv2\core\core_c.h:48:
C:/Users/SOLO/Documents/Github/ocv/vc15/install/opencv/include\opencv2/core/types_c.h:929:13: warning: implicit
      declaration of function 'cvRound' is invalid in C99 [-Wimplicit-function-declaration]
    ipt.x = cvRound(point.x);
            ^
1 warning generated.
I-needs-reduced-test-case msvc

All 6 comments

Weird, does it happen if you run with -target <an-msvc-target>?

Yes, it's indeed the wrong target. Use of -target stable-x86_64-pc-windows-msvc is the right solution. Great job, thank you

Glad to help!

Please consider making a PR adding it to the FAQ, I don't have windows so my chances to mess it up are high. Thanks for filing again!

@emilio how can it be done? I see faq.md is autogenerated.

Only the table of contents (the bits between <!-- START and <!-- END are autogenerated, the rest can be edited at will :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DuckerMan picture DuckerMan  路  6Comments

jonhoo picture jonhoo  路  8Comments

maurer picture maurer  路  3Comments

fitzgen picture fitzgen  路  6Comments

fpagliughi picture fpagliughi  路  9Comments