Coder Social home page Coder Social logo

ffi_factorial's Introduction

Dart FFI for Writing C Code

Welcome to the Dart FFI project! This repository contains code and examples demonstrating how to use Dart FFI (Foreign Function Interface) to call C code from Dart.

Overview

In this project, you'll learn how to:

  • Set up your environment for using Dart FFI.
  • Write and compile C code.
  • Integrate and call C functions from your Dart application.

Getting Started

Prerequisites

Before you begin, ensure you have the following installed on your machine:

  • Dart SDK
  • C compiler (such as GCC for Linux/macOS or MinGW for Windows)

Setup

  1. Clone the repository:

    git clone https://github.com/khkred/ffi_factorial.git
    cd ffi_factorial
  2. Compile the C code:

    Compile the C code into a shared library. The commands may vary depending on your operating system:

    • Linux/macOS:

      gcc -shared -o libfactorial.so factorial.c
    • Windows:

      gcc -shared -o libfactorial.dll factorial.c
  3. Run the Dart application:

    dart run

Usage

The Dart application will prompt you to enter a number to calculate its factorial using the native C function. Simply follow the on-screen instructions.

Code Structure insde bin

  • factorial.c: Contains the C code for calculating the factorial.
  • libfactorial.so/libfactorial.dll/libfactorial.dylib: The compiled shared library.
  • ffi_factorial.dart: The Dart code that uses FFI to call the C function.
  • factorial_user_input.dart: The Dart code that asks for an user input in order to calcualte the factorial

Contributing

Contributions are welcome! If you have any suggestions or improvements, please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

Special thanks to the Dart and Flutter communities for their continuous support and inspiration.

Author

Links

ffi_factorial's People

Contributors

khkred avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.