c-interop
Version, currently master branch1 version
- master branchlatestSep 22, 2017
github.com/ethagnawl/crystal-c-interop-demo
Experimenting with Crystal's C interop capabilities
Installation
# Add this to your shard.yml
dependencies:
c-interop:
github: ethagnawl/crystal-c-interop-demo
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.21.0- License
- MIT
- Author
- Peter Doherty
- Target
c-interopfrom src/c-interop.cr
Dependencies
This version declares no dependencies.
README
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 && popdcrystal build src/c-interop.cr
Run
./c-interop # => Hello, world!
Interesting bits
- ./src/c/lib/hello.c
- ./src/c-interop.cr
Resources
- http://www.cs.dartmouth.edu/~campbell/cs50/buildlib.html
- https://randu.org/tutorials/c/libraries.php
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Sep 22, 2017
- Crystal
0.21.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/ethagnawl/crystal-c-interop-demo
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 1