Skip to content

Why can't bindgen find libclang.dll? #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Boscop opened this issue Mar 15, 2018 · 9 comments
Closed

Why can't bindgen find libclang.dll? #1276

Boscop opened this issue Mar 15, 2018 · 9 comments

Comments

@Boscop
Copy link

Boscop commented Mar 15, 2018

Why can't bindgen find libclang.dll?

D:\3rdparty\reaper_extension_sdk\jmde>bindgen reaper_plugin_functions.h -o reaper.rs
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared libra
ry at D:\\Program Files\\LLVM\\bin\\libclang.dll could not be opened: %1 is not
a valid Win32 application. (os error 193)"', libcore\result.rs:945:5
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: BaseThreadInitThunk
  15: RtlInitializeExceptionChain
  16: RtlInitializeExceptionChain

Btw, the file "D:\Program Files\LLVM\bin\libclang.dll" exists and has version 4.0.0.0.
An earlier version of bindgen cli was working without problems on this system.

@emilio
Copy link
Contributor

emilio commented Mar 15, 2018

If this is a regression, could you please try different versions to figure out which regressed?

This should probably be reported upstream to the clang-sys crate, though looks like your DLL is borked in some way.

@emilio
Copy link
Contributor

emilio commented Mar 15, 2018

This may even be a regression in libloading itself I guess.

@Boscop
Copy link
Author

Boscop commented Mar 16, 2018

Thanks for the quick reply. I tried version 0.30.0 (cargo install -f --vers 0.30.0 bindgen, it seems to load libclang.dll but fails on C++ constructs.. Do I have to pass a flag to enable C++ support?

D:\3rdparty\reaper_extension_sdk\jmde>bindgen reaper_plugin_functions.h -o reaper.rs
./reaper_plugin.h:149:1: error: unknown type name 'class'
./reaper_plugin.h:149:26: error: expected ';' after top level declarator
./reaper_plugin.h:174:1: error: unknown type name 'class'
./reaper_plugin.h:174:21: error: expected ';' after top level declarator
./reaper_plugin.h:204:3: error: unknown type name 'MIDI_eventlist'
./reaper_plugin.h:248:3: error: unknown type name 'MIDI_eventlist'
./reaper_plugin.h:258:1: error: unknown type name 'class'
./reaper_plugin.h:258:17: error: expected ';' after top level declarator
./reaper_plugin.h:302:3: error: unknown type name 'bool'
./reaper_plugin.h:309:3: error: unknown type name 'PCM_source'
./reaper_plugin.h:375:3: error: unknown type name 'PCM_source'
./reaper_plugin.h:376:3: error: unknown type name 'PCM_source'
./reaper_plugin.h:389:1: error: unknown type name 'class'
./reaper_plugin.h:389:26: error: expected ';' after top level declarator
./reaper_plugin.h:439:3: error: unknown type name 'bool'
./reaper_plugin.h:449:1: error: unknown type name 'class'
./reaper_plugin.h:449:15: error: expected ';' after top level declarator
./reaper_plugin.h:490:3: error: unknown type name 'PCM_sink'
./reaper_plugin.h:490:91: error: unknown type name 'bool'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
./reaper_plugin.h:149:1: error: unknown type name 'class', err: true
./reaper_plugin.h:149:26: error: expected ';' after top level declarator, err: t
rue
./reaper_plugin.h:174:1: error: unknown type name 'class', err: true
./reaper_plugin.h:174:21: error: expected ';' after top level declarator, err: t
rue
./reaper_plugin.h:204:3: error: unknown type name 'MIDI_eventlist', err: true
./reaper_plugin.h:248:3: error: unknown type name 'MIDI_eventlist', err: true
./reaper_plugin.h:258:1: error: unknown type name 'class', err: true
./reaper_plugin.h:258:17: error: expected ';' after top level declarator, err: t
rue
./reaper_plugin.h:302:3: error: unknown type name 'bool', err: true
./reaper_plugin.h:309:3: error: unknown type name 'PCM_source', err: true
./reaper_plugin.h:375:3: error: unknown type name 'PCM_source', err: true
./reaper_plugin.h:376:3: error: unknown type name 'PCM_source', err: true
./reaper_plugin.h:389:1: error: unknown type name 'class', err: true
./reaper_plugin.h:389:26: error: expected ';' after top level declarator, err: t
rue
./reaper_plugin.h:439:3: error: unknown type name 'bool', err: true
./reaper_plugin.h:449:1: error: unknown type name 'class', err: true
./reaper_plugin.h:449:15: error: expected ';' after top level declarator, err: t
rue
./reaper_plugin.h:490:3: error: unknown type name 'PCM_sink', err: true
./reaper_plugin.h:490:91: error: unknown type name 'bool', err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'Unable to generate bindings: ()', libcore\result.rs:9
45:5
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: BaseThreadInitThunk
  18: RtlUserThreadStart

Update: same behavior with v0.32.0

@Boscop
Copy link
Author

Boscop commented Mar 16, 2018

Just tried with v0.33.0, it shows this:
image

@Michael-F-Bryan
Copy link
Contributor

Michael-F-Bryan commented Mar 22, 2018

I just encountered this at work. I know clang itself is installed, but every time I try to run bindgen it fails saying %1 is not a valid Win32 application.

C:\Users\mbryan> bindgen --version
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at C:\\Program Files (x86)\\LLVM\\bin\\libclang.dll could not be opened: %1 is not a valid Win32 application. (os error 193)"', libcore\result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
C:\Users\mbryan> clang --version
clang version 5.0.1 (tags/RELEASE_501/final)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\LLVM\bin

I tried re-running with RUST_BACKTRACE="full" but it's a release build without debug symbols available, so the backtrace is essentially useless.

EDIT: I just added bindgen as a build script and managed to get a backtrace.

errors.txt

@emilio
Copy link
Contributor

emilio commented Mar 23, 2018

So, the error comes from here:

https://github.com/KyleMayes/clang-sys/blob/e6948cb8e7d6d67d6eb409aa788699b401ef9585/src/link.rs#L122

I don't have a machine that reproduces the issue but if it worked before chances are that this is a libloading regression (cc @nagisa). Probably an issue should be filed there.

@Michael-F-Bryan
Copy link
Contributor

I just noticed that under clang --version it says Target: i686-pc-windows-msvc. It may be the case that I installed clang as a 32-bit program (the application I'm interfacing with is 32-bit) and then I've told rustup to target 64-bit during development.

I'm not sure whether this is actually the case, but when I'm back at work on Monday I'll check whether that DLL is 32-bit or 64-bit. It could be that the "%1 is not a valid Win32 application" error is a red herring or not the root cause, and the actual issue is you can't load the DLL because it's got a different wrong word size to the build script/bindgen program.

@Boscop, does any of this sound familiar?

@Boscop
Copy link
Author

Boscop commented Mar 24, 2018

But I didn't change the libclang.dll since bindgen worked, and the old bindgen was installed the same way so it must also have been 64 bit..
Is there a way I can cargo install the 32 bit version to test?

@KyleMayes
Copy link
Contributor

v0.23.0 of clang-sys has been released to address this issue.

The issue was indeed the selection of 32-bit DLLs for a 64-bit build (or vice-versa) and the fix was to skip DLLs for the incorrect architecture while searching for clang.dll / libclang.dll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants