I’m using Dart FFI for the first time, and I’ve started writing a small C++ library that I want to access using dart:ffi.
I’m using the Visual Studio build tools, as I’m only targeting Windows, and my project is set up like this:
- my_flutter_project_root
- lib
- (etc.)
- native
- my_native_solution
- include
- [all the headers from dart-sdk/include]
- libs
- dart.lib (from dart-sdk/bin)
- my_source_code
- x64
- Release
- my_native_library.dll
- my_native_solution.sln
If I remove the dependency on dart.lib, I’m able to load
ffi.DynamicLibrary.open(path.join(Directory.current.path, 'native', 'my_native_solution', 'x64', 'Release', 'my_native_library.dll'))
just fine, however, once I add the dependency, the code fails with
════════ Exception caught by scheduler library ═════════════════════════════════
The following ArgumentError was thrown during a scheduler callback:
Invalid argument(s): Failed to load dynamic library 'my_native_library.dll': The specified module
could not be found.
(error code: 126)
From the answers I found I can tell that this is apparently caused by the loader not being able to locate the library’s dependencies, but I couldn’t figure out how to resolve this issue.
I’d appreciate help on how I need to structure my project in order to avoid this.
3