# Using C Dynamic Libraries In Go Programs

DevFeed: [Using C Dynamic Libraries In Go Programs](<https://devfeed.tech/articles/using-c-dynamic-libraries-in-go-programs-22067.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/08/using-c-dynamic-libraries-in-go-programs.html>)

Published: 2013-08-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [ncurses](<https://devfeed.tech/topics/ncurses.md>), [Text-based user interface](<https://devfeed.tech/topics/tui.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [console](<https://devfeed.tech/topics/console.md>), [IO](<https://devfeed.tech/topics/io.md>), [make](<https://devfeed.tech/topics/make.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [c](<https://devfeed.tech/tags/c.md>), [c-c-plus-plus](<https://devfeed.tech/tags/c-c-plus-plus.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [code](<https://devfeed.tech/tags/code.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [input](<https://devfeed.tech/tags/input.md>), [keyboard](<https://devfeed.tech/tags/keyboard.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [library](<https://devfeed.tech/tags/library.md>), [linux](<https://devfeed.tech/tags/linux.md>), [mac](<https://devfeed.tech/tags/mac.md>), [make](<https://devfeed.tech/tags/make.md>), [ncurses](<https://devfeed.tech/tags/ncurses.md>), [program](<https://devfeed.tech/tags/program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [services](<https://devfeed.tech/tags/services.md>), [static](<https://devfeed.tech/tags/static.md>)

## AI overview

To read keystrokes without waiting for Enter in a Go console game, the author turned to C and ncurses after two Go libraries they tried did not work. They first built a standalone C test using ncurses: initialize terminal input with `initscr`, `noecho`, `cbreak`, and `keypad`, read characters with `getch`, then restore the terminal with `endwin`. The excerpt ends as the author begins showing a GCC makefile; it does not provide the subsequent Go integration steps or establish that the build command shown is complete.

## Source excerpt

My son and I were having fun last weekend building a console based game in Go. I was recreating a game from my youth, back when I was programming on a Kaypro II. View linked image: kayproii I loved this computer. I would write games in BASIC on it all day and night. Did I mention it was portable. The keyboard would strap in and you could carry it around. LOL. But I digress, back to my Go program. I figured out a way to use the VT100 escape character codes to draw out a simple screen and started programming some of the logic. Then something horrible happened and I had a major flashback. I could not get input from stdin without hitting the enter key. Ahhhhh I spent all weekend reading up on how to make this happen. I even found two Go libraries that had support for this but they didn't work. I realized that if I was going to make this happen I needed to build the functionality in C and link that to my Go program. After a 4 hour coding session at the local Irish pub, I figured it out. I would like to thank Guinness for the inspiration and encouragement I needed. Understand that for the past 10 years I have been writing windows services in C#. For 10 years before that I was writing C/C++ but on the Microsoft stack. Everything I was reading: gcc, gco, static and shared libraries on the Mac and Linux, etc, was foreign to me. I had a lot to learn and still do. After all my research it became clear I needed to use the ncurses dynamic library. I decided to write a simple program in C using the library. If I could make it work in a compiled C program, I was sure I could get it to work in Go. View linked image: Screen Shot