0

我正在尝试使用 bindgen 生成与 Qt6 的绑定。我已经按照这个答案尝试了这个: -

let bindings = bindgen::Builder::default()
    .header("exclient.hpp")
    .clang_arg("
        -I/usr/include/qt6
        -I/usr/include/qt6/QtCore
        -I/usr/include/qt6/QtGui
        -I/usr/include/qt6/QtQml
        -I/usr/include/qt6/QtQuick
    ")
    .parse_callbacks(Box::new(bindgen::CargoCallbacks))
    .generate()
    .expect("Unable to generate bindings");

但是当我尝试编译它时,我收到以下错误:-


  --- stderr
  /home/hilomen/Development/qtrusttest/target/debug/build/exclient3-d982a3579dd42390/out
  warning: 
              -I/usr/include/qt6
              -I/usr/include/qt6/QtCore
              -I/usr/include/qt6/QtGui
              -I/usr/include/qt6/QtQml
              -I/usr/include/qt6/QtQuick
          : 'linker' input unused [-Wunused-command-line-argument]
  exclient.hpp:3:10: fatal error: 'QObject' file not found
  warning: 
              -I/usr/include/qt6
              -I/usr/include/qt6/QtCore
              -I/usr/include/qt6/QtGui
              -I/usr/include/qt6/QtQml
              -I/usr/include/qt6/QtQuick
          : 'linker' input unused [-Wunused-command-line-argument], err: false
  exclient.hpp:3:10: fatal error: 'QObject' file not found, err: true

我可以确认/usr/include/qt6/QtCore/QObject文件确实存在

4

1 回答 1

1

愚蠢的我,我应该使用 clang_args 而不是 clang_arg

let bindings = bindgen::Builder::default()
    .header("exclient.hpp")
    .clang_args(&[
        "-I/usr/include/qt6",
        "-I/usr/include/qt6/QtCore",
        "-I/usr/include/qt6/QtGui",
    ])
    .parse_callbacks(Box::new(bindgen::CargoCallbacks))
    .generate()
    .expect("Unable to generate bindings");
于 2021-03-09T13:25:19.153 回答