I wanted to create a dll to use cpp-packages in Dart. I was able to create the dll-file with CMake, but when I tried to open it in Dart it didn't work. In my cpp file I already had a function that when exported into a dll worked, but after I added another include-statement (#include <json/json.h>) and exported to a dll it didn't work anymore: The dll got compiled, but Dart couldn't open it anymore. This is the error I got in Dart:
Unhandled exception:
Invalid argument(s): Failed to load dynamic library './build/Debug/library.dll': error code 126
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2 main (file:///C:/development/cpp/dll_libraries/library/main.dart:13:32)
<asynchronous suspension>
In my CMakeLists.txt-File I have the following Code:
set(JSONCPP_DIR "C:/development/cpp/packages/vcpkg/packages/jsoncpp_x64-windows")
set(JSONCPP_LIBRARY "C:/development/cpp/packages/vcpkg/packages/jsoncpp_x64-windows/lib/jsoncpp.lib")
include_directories($ENV{other_CPP_SDK_DIR}/include ${JSONCPP_DIR}/include)
target_sources(${LIBRARY} PRIVATE ${DEF_FILES})
target_link_libraries(${LIBRARY} PUBLIC ${other_libs} ${ADDITIONAL_LIBS} ${JSONCPP_LIBRARY})
I think the reason is, that Dart is not able to use the content of the package jsoncpp to execute the functions in the dll, but CMake compiled the dll.
I tried to inspect the dll, but everything seemed to be normal:
Dump of file build\Debug\library.dll
File Type: DLL
Section contains the following exports for library.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
2 number of functions
2 number of names
ordinal hint RVA name
1 0 0000F2BD init= @ILT+58040(?init@@YA_NXZ)
2 1 0001F5FA writeDatabase = @ILT+124405(?writeDatabase@@YA_NXZ)
Summary
1000 .00cfg
397000 .data
A000 .idata
2000 .pdata
D8B000 .rdata
49000 .reloc
1000 .rsrc
1713000 .text
1000 .tls
Do you have any idea how I can fix this, so that Dart is able to open the dll?