How to statically link C/C++ static library (.a) in golang

2,835 views
Skip to first unread message

prajakta....@gmail.com

unread,
Aug 17, 2015, 8:18:46 PM8/17/15
to golang-nuts
Hello 

I am able to link the C library (.so) dynamically in my go code by doing following

setting LD_LIBRARY_PATH and exporting the path to .so file
setting the CFLAGS and LDFLAGS as below while building go code

CGO_CFLAGS="-I$(GOPATH)/<pathtoinclude>" CGO_LDFLAGS="-L$(GOPATH)/<path where the .so file is present>" go build

go code looks like

/*
#cgo LDFLAGS: -l<xxx>
#include <stdlib.h>
#include "c.h"
*/
import "C"
...



This works very well. 

My aim now is to link the static library to the go code. I searched on web, but could not find right solution
Please suggest

andrey mirtchovski

unread,
Aug 17, 2015, 8:29:46 PM8/17/15
to prajakta....@gmail.com, golang-nuts
#cgo LDFLAGS: /path/to/library/file.a

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages