mixing C with GO

272 views
Skip to first unread message

bee f

unread,
May 20, 2014, 5:54:24 PM5/20/14
to golan...@googlegroups.com

I'm working with some existing code that is C based.   I'd like to add some new functionality but would prefer to write this new functionality in GO instead of C.

In this C code, is it possible to invoke a function call (with a few parameters) that is implemented in GO?  I'm guessing minimally I'd need to create a .o file for the GO code (not sure if this is possible) and then hope the linking of C and GO code works.   Is this an option?   Steps?

If the above isn't an option, might there be some other way to blend the C code with new code written in GO?     (The C code is dozens of .c and .h files and 20k lines of code-- so rewriting isn't practical).

Thanks

James Bardin

unread,
May 20, 2014, 6:08:57 PM5/20/14
to golan...@googlegroups.com
Currently, Go cannot create any shared libraries.

It may however be possible to rework your program to run from Go, which could call the existing functionality via cgo.

Mateusz Czapliński

unread,
May 21, 2014, 4:44:58 AM5/21/14
to golan...@googlegroups.com
On Tuesday, May 20, 2014 11:54:24 PM UTC+2, bee f wrote:
I'm working with some existing code that is C based.   I'd like to add some new functionality but would prefer to write this new functionality in GO instead of C.

If you're using gcc, I think your best bet would be to try to use gccgo. I think it's not really worthwhile to explore other options, unless you confirm that you're not using gcc, or you'll have some serious problems with gccgo. Till this time, I believe any concerns about Go's support for shared libraries or cgo could be put on hold.

/Mateusz.


Reply all
Reply to author
Forward
0 new messages