|
| 1 | +# Frequently Asked Questions |
| 2 | + |
| 3 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 4 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 5 | + |
| 6 | + |
| 7 | +- [Why isn't `bindgen` generating methods for this whitelisted class?](#why-isnt-bindgen-generating-methods-for-this-whitelisted-class) |
| 8 | +- [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions) |
| 9 | +- [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) |
| 10 | + |
| 11 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 12 | + |
| 13 | +### Why isn't `bindgen` generating methods for this whitelisted class? |
| 14 | + |
| 15 | +Are the methods `inline` methods, or defined inline in the class? For example: |
| 16 | + |
| 17 | +```c++ |
| 18 | +class Dooder { |
| 19 | + public: |
| 20 | + // Function defined inline in the class. |
| 21 | + int example_one() { return 1; } |
| 22 | + |
| 23 | + // `inline` function whose definition is supplied later in the header, or in |
| 24 | + // another header. |
| 25 | + inline bool example_two(); |
| 26 | +}; |
| 27 | + |
| 28 | +inline bool Dooder::example_two() { |
| 29 | + return true; |
| 30 | +} |
| 31 | +``` |
| 32 | +
|
| 33 | +If so, see |
| 34 | +["Why isn't `bindgen` generating bindings to inline functions?"](#why-isnt-bindgen-generating-bindings-to-inline-functions) |
| 35 | +
|
| 36 | +If not, consider filing an issue! |
| 37 | +
|
| 38 | +### Why isn't `bindgen` generating bindings to inline functions? |
| 39 | +
|
| 40 | +These functions don't typically end up in object files or shared libraries with |
| 41 | +symbols that we can reliably link to, since they are instead inlined into each |
| 42 | +of their call sites. Therefore, we don't generate bindings to them, since that |
| 43 | +creates linking errors. |
| 44 | +
|
| 45 | +However, if you are compiling the C/C++ yourself (rather than using a system |
| 46 | +shared library, for example), then you can pass `-fkeep-inline-functions` or |
| 47 | +`-fno-inline-functions` to `gcc` or `clang`, and invoke `bindgen` with either |
| 48 | +the `bindgen::Builder::generate_inline_functions` method or the |
| 49 | +`--generate-inline-functions` flag. |
| 50 | +
|
| 51 | +Note that these functions and methods are usually marked inline for a reason: |
| 52 | +they tend to be hot. The above workaround makes them an out-of-line call, which |
| 53 | +might not provide acceptable performance. |
| 54 | +
|
| 55 | +### Does `bindgen` support the C++ Standard Template Library (STL)? |
| 56 | +
|
| 57 | +Sort of. A little. Depends what you mean by "support". |
| 58 | +
|
| 59 | +Most functions, methods, constructors, and destructors are inline in the |
| 60 | +STL. That ties our hands when it comes to linking: ["Why isn't `bindgen` generating bindings to inline functions?"](#why-isnt-bindgen-generating-bindings-to-inline-functions) |
| 61 | +
|
| 62 | +As far as generating opaque blobs of bytes with the correct size and alignment, |
| 63 | +`bindgen` can do pretty well. This is typically enough to let you use types that |
| 64 | +transitively contain STL things. We generally recommend marking `std::.*` as |
| 65 | +opaque, and then whitelisting only the specific things you need from the library |
| 66 | +you're binding to that is pulling in STL headers. |
0 commit comments