crystal-c-interop-demo

Experimenting with Crystal's C interop capabilities

Overview

After having been intrigued by Crystal's C interop facilities while reading through the docs, I decided to write a C library (my first!) and try linking it into a program. The library provides one function (hello), which accepts one parameter and uses it to print a heartfelt message (e.g. Hello, world!).

I ran into one issue along the way, but I believe that was a result of my ignorance about the C library ecosystem. I also went off the rails a bit because I was using a static library and not something available via pkg-config. Either way, once I figured out how to supply the path to my static library to @[Link], everything Just Worked.

Build

  • pushd ./src/c && make && popd
  • crystal build src/c-interop.cr

Run

./c-interop # => Hello, world!

Interesting bits

  • ./src/c/lib/hello.c
  • ./src/c-interop.cr

Resources

Repository

crystal-c-interop-demo

Owner
Statistic
  • 2
  • 0
  • 1
  • 0
  • 0
  • over 6 years ago
  • February 24, 2017
License

MIT License

Links
Synced at

Sat, 04 May 2024 08:54:15 GMT

Languages