Skip to content
Branch: master
Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.
hello_world platform Sep 24, 2019
primitives defs, nmake files added Sep 24, 2019
structs defs, nmake files added Sep 24, 2019
system-command Update macos.dart Sep 10, 2019
.gitignore gitignore on windows Sep 24, 2019 gcc x64 Sep 24, 2019

Experiments with Dart FFI

A series of simple examples demonstrating how to call C libraries from Dart.

Please note that the Dart FFI API is in active development and likely to change before release. This code is designed to work with Dart version 2.5.0.


The C make files are (currently) written to work on a Mac. To compile the libraries, go to the c/ folder in each subproject and run:

make dylib

A .dylib file should be created in the parent folder. Navigate to that and run the dart file.

On Windows:

A dll can be created in two ways.

  1. Using gcc

    In the subproject's c/ run

    make dll

    Install gcc from msys2, a more detailed tutorial.

    And add it to path eg: C:\msys64\mingw64\bin\.

    And make sure gcc -dumpmachine gives something like x86_64-w64-mingw32 but NOT i686-w64-mingw32 eg: C:\msys64\mingw64\bin\gcc.exe

  2. Using cl from the Visual Studio build. Follow the docs to be able to run nmake.exe from cmd line.

    • Visual Studio needs to be installed with c/c++ checked.
    • Then add \path\to\VC\Auxiliary\Build to PATH eg: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build
    • You can now run vcvars32.bat , vcvars64.bat , vcvarsx86_amd64.bat etc.from the command line as mentioned in the docs.
    • Then choose your setup and run vcvars*.bat and now, cl.exe , nmake.exe can be used from the command line.

    In the subproject's c/ run

    nmake -f Nmakefile dll

    A .dll file should be created in the parent folder. Navigate to that and run the dart file.

    Only applicable if on Windows:

    The c/c++ functions should be exported or dart will not be able to lookup the function definitions.

    This can be done in two ways.

    • Using the keyword __declspec(dllexport) in the class/function's definition docs

    • Creating a .def file docs

    In every subproject's c/ directory there is .def file.

    That might be neccessary (depending on whether the functions were already exported) to create a dynamic link library dll on Windows. As it's used to define what functions are to be exported when creating a dll.

    More details on how to write/generate one here

You can’t perform that action at this time.