cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

C header doesn't include types for uintptr_t

Open Firstyear opened this issue 4 years ago • 4 comments

If you have a c file such as:

#include <cbindings.h>

int main(...) {
    ...
}

And you use cbindings.h as emitted by cbindgen with language "C" provided, this will not compile due to:

 unknown type name ‘uintptr_t’
   10 | uintptr_t do_nothing_rust();
      | ^~~~~~~~~

This is due to a missing header (probably inttypes.h) in cbindings.h

Cbindgen should itself include inttypes.h (and all other relevant types) for allow C language emitted headers to work.

Firstyear avatar Oct 03 '19 04:10 Firstyear

Hmmm, which c compiler / library are you using? We compile all our tests to verify that they are valid C / C++ code, and we do have test-cases for uintptr_t... See tests/expectations/tag/enum.c for example.

emilio avatar Oct 03 '19 05:10 emilio

I'm using OpenSUSE tumbleweed with gcc9. You could try this with docker run opensuse/tumbleweed:latest /bin/sh; zypper in -y gcc;

Firstyear avatar Oct 03 '19 05:10 Firstyear

Do the cbindgen tests pass for you there? I'm surprised since I use glibc and gcc9 locally and it works.

Anyhow probably trivial to just expand the set of default includes, want to send a patch that works for you? The code to emit these is in src/bindgen/bindings.rs.

emilio avatar Oct 11 '19 08:10 emilio

see: https://en.cppreference.com/w/c/types/integer https://en.cppreference.com/w/cpp/types/integer

KangLin avatar Oct 29 '22 13:10 KangLin