After skimming over the mailing list and the issues, I've -- like
some other poster in March -- concluded that: currently it is
impossible to statically link anything touching `import "C"`.
Although someone suggested that if we "embed" the C code directly
into the `.go` file it should work. Unfortunately it is not the case.
Even the simplest code:
~~~~
package main
import "C"
func main () {
}
~~~~
When built with `go build -ldflags -d ./cgo-static-3.go`, fails with:
A) Is it safe to assume that in an acceptable period of time such
a feature would be implemented? (An acceptable period would be about
one year or so.)
B) Which will there be any serious limitations? (Like would it
work for C++ libraries?)
On Mon, May 28, 2012 at 4:45 PM, minux <minu...@gmail.com> wrote:Hmmm... This could work for me. (The library I try to statically
>> There this project wich uses the golang C compilers to compile the Lua
>> interpreter and link that with Go,
>>
>> https://github.com/akavel/goluago
>>
>> I don't know if this make any difference in allowing static linking the C
>> code.
>
> Yes, this is another option. But, you must make sure your code is almost C89
> and compilable by Plan 9 cc. Also, it can't use much external library (libc
> included),
> as you must emulate them all in Go.
embed is very small and simple and uses only a few syscalls which I
could implement in ASM)...
Where would I find some documentation on how I could do this? (Or
where exactly in the `luago`, as I've not found it in a quick search?)
P.S.: What does `CL` stand for? (I've beaten my head and I
couldn't figure it out? "Code ?something?"?)
implementation which is pretty small (I only need a fraction of it). IThanks for the feedback. (The library is actually the `tinycdb`
think I'll even rewrite it in pure Go maybe.)
I've made a simple experiment and it works:
https://github.com/cipriancraciun/volution-do/tree/5612165ec7aed7eb9857e8dff43c6ec3eed1d404/sources/experiments/c-static
Although the call semantic took me some time to track down.
(Thanks to an older email of yours "Linking in a small C object" I've
nailed it.)
Maybe this should be documented somewhere?
Thanks for the feedback. (The library is actually the `tinycdb`
implementation which is pretty small (I only need a fraction of it). I
think I'll even rewrite it in pure Go maybe.)
Thanks,
Ciprian.