0

I am trying to generate bindings for libtorrent using ffigen.

The output of dart run ffigen --config ffigen.yaml is something like this

Input Headers: [src2/include/libtorrent/libtorrent.hpp]
[SEVERE] : Header src2/include/libtorrent/libtorrent.hpp: Total errors/warnings: 1.
[SEVERE] :     src2/include/libtorrent/libtorrent.hpp:4:10: fatal error: 'libtorrent/add_torrent_params.hpp' file not found [Lexical or Preprocessor Issue]
Finished, Bindings generated in /.../flutter/projects/dart_libtorrent/lib/bindings_generated.dart

This is my ffigen.yaml file

# Run with `dart run ffigen --config ffigen.yaml`.
name: DartLibTorrentBindings
description: |
  Bindings for `LibTorrent`.

  Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
output: "lib/bindings_generated.dart"
headers:
  entry-points:
    - "src2/include/libtorrent/libtorrent.hpp"
preamble: |
  // ignore_for_file: always_specify_types
  // ignore_for_file: camel_case_types
  // ignore_for_file: non_constant_identifier_names
comments:
  style: any
  length: full

What should I do?

I was following this tutorial:

https://blog.logrocket.com/dart-ffi-native-libraries-flutter/

Davenchy
  • 47
  • 6

1 Answers1

-2

The problem is clang can't find headers because it needs an extra include directory.

In my case I specified the headers location using compiler-opts option to pass the flag -I to the compiler.

So I added the next lines to my ffigen.yaml

compiler-opts:
  - '-Isrc2/include/'

The answer can be found here: https://github.com/dart-lang/ffigen/issues/452#issuecomment-1230829422

Davenchy
  • 47
  • 6