0

I'm trying to create a Dart FFI plugin for the GStreamer library to use it in my Flutter application on Windows, with plans to expand to other platforms in the future. Since GStreamer is written in C, I thought it would be relatively straightforward to create bindings for it.

To get started, I downloaded the pre-compiled dynamic library from the official website, specifically the MSVC 64-bit (VS 2019, Release CRT) 1.22.4 runtime installer. However, I'm having trouble getting the library to load properly.

When I try to run the Dart FFI plugin, I get the following error message:

Invalid argument(s): Failed to load dynamic library 'gstreamer-1.0-0.dll': error code 126

I've checked that the DLL file is present in the correct directory and I've also added the DLL to my CMakeLists.txt file for the plugin.

Here is Windows CMakeLists.txt file:

cmake_minimum_required(VERSION 3.14)

set(PROJECT_NAME "gstreamer")
project(${PROJECT_NAME} LANGUAGES CXX)

set(PLUGIN_NAME "gstreamer_plugin")

list(APPEND PLUGIN_SOURCES
  "gstreamer_plugin.cpp"
  "gstreamer_plugin.h"
)

add_library(${PLUGIN_NAME} SHARED
  "include/gstreamer/gstreamer_plugin_c_api.h"
  "gstreamer_plugin_c_api.cpp"
  ${PLUGIN_SOURCES}
)

apply_standard_settings(${PLUGIN_NAME})

set_target_properties(${PLUGIN_NAME} PROPERTIES
  CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)


target_include_directories(${PLUGIN_NAME} INTERFACE
  "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)

# Eveything is Dart's default plugin staff
set(gstreamer_bundled_libraries
  # Only added this line
  "${CMAKE_CURRENT_SOURCE_DIR}/gstreamer-1.0-0.dll"
  PARENT_SCOPE
)

Here is my flutter environment setup:

Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1928], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.4)
[√] Android Studio (version 2022.2)
[√] VS Code (version 1.79.2)
[√] Connected device (3 available)
[√] Network resources

What could be causing this issue, and how can I resolve it? Is there anything else I can try to get the dynamic library working properly in my Dart FFI plugin on Windows?

NattyPluz
  • 26
  • 3
  • This just means that one of the other dlls in D:\gstreamer\1.0\msvc_x86_64\bin is required by gstreamer-1.0-0.dll, but windows cannot find it. Make sure that the above bin folder is in your path. (If it is in your path you should be able to type `gst-inspect-1.0.exe` in a command tool and get valid output.) – Richard Heap Jul 10 '23 at 02:33
  • I have included `D:\gstreamer\1.0\msvc_x86_64\bin` to `Environment path`. `gst-inspect-1.0.exe` works fine in cmd. But I see no change in the Dart plugin project, the error still exists. – NattyPluz Jul 10 '23 at 05:08
  • 1
    Create a plain Dart project first and get this to work: `import 'dart:ffi'; void main() { final dylib = DynamicLibrary.open( 'D:\\gstreamer\\1.0\\msvc_x86_64\\bin\\gstreamer-1.0-0.dll'); }` – Richard Heap Jul 10 '23 at 13:02
  • I wonder why you are creating any C source of your own. If the dll has a C interface as you state, most of the time you should be able to simply open it and wrap its methods in Dart - i.e. normal Dart ffi. – Richard Heap Jul 10 '23 at 13:06

0 Answers0