Have your eyes set on the perfect C library for your project? Can't find a wrapper for it in Nim? Look no further! Futhark aims to allow you to simply import C header files directly into Nim, and allow you to use them like you would from C without any manual intervention. It's still in an alpha state, but it can already wrap many complex header files without any rewrites or pre-processing. import futhark # Tell futhark where to find the C libraries you will compile with, and what # header files you wish to import. importc: absPath "/usr/lib/clang/12.0.1/include" path "../stb" define STB_IMAGE_IMPLEMENTATION "stb_image.h" # Tell Nim how to compile against the library. If you have a dynamic library # this would simply be a `--passL:"-l<library name>` static: writeFile("test.c", """ #define STB_IMAGE_IMPLEMENTATION #include "../stb/stb_image.h" """) {.compile: "test.c".} # Use the library just like you would in C! var width, height, channels: cint var image = stbi_load("futhark.png", width.addr, height.addr, channels.addr, STBI_default.cint) if image == nil: echo "Error in loading the image" quit 1 echo "Loaded image with a width of ", width, ", a height of ", height, " and ", channels, " channels" stbi_image_free(image) Run
This is a project I've been working on for the past couple weeks. It allows you to import C files directly in Nim code and just use all procedures and structures without any modification. It aims to bridge the gap between Nim and C and allow you to use any library without having to create any wrappers!