What is the official way to use cgo? I know you need mingw
installed, but I do have mingw installed and that does not
seem to be enough.
What else is necessary? If we can collect that information here,
then we can turn it into a document.
Thanks.
Russ
What is the status of cgo on Windows (issue 1741)?
I know that there are some issues with missing symbols.
Alex has reported missing chkstk, which I assume is for
gcc's stack buffer overflow checks, and I have tried to
run cgo on my Windows 7 install and gotten errors about
missing _assert.
Alex, what version of mingw are you using (32-bit, not TDM)?
AFAIK, __chkstk is from the MSVC runtime not gcc. Is __chkstk being
resolved with the dynamic linking you mention because there's a msvc
library being pulled in? You can suppress __chkstk with the /Gs option
under MSVC but no idea what the gcc equivalent is, or if there is one.
http://support.microsoft.com/kb/100775
-joe
I just found a reference to this option -mno-stack-arg-probe
If we pass -fpic then there should be no static linking involved.
Unfortunately, we don't pass -fpic on Windows because then
the compiler complains that it is redundant.
Note sure if this is helpful but from > gcc -v --help in ld.exe
section it lists
-Bdynamic, -dy, -call_shared Link against shared libraries
Russ
Where is libgcc.a? What is in it? What is its license?
Can we just copy it into runtime/cgo.a and be done with it?
> Where is libgcc.a? What is in it? What is its license?
> Can we just copy it into runtime/cgo.a and be done with it?
libgcc.a is under a GPL+exception license. Copying it and maintaining
the copy would be a pain because it is built in a funny way.
__chkstk is always statically linked because it is called in a special
way that preserves the argument registers. Dynamically link it might
cause the dynamic call to clobber those registers, which would of course
break the program.
I'm not sure what the command is that is failing. For cgo's purposes
all we really need to know is that __chkstk is special. So one approach
is to just make it special: recognize it in cgo. Another approach is to
explicitly link against -lgcc; since cgo already assumes that gcc is
available, it seems to me that that should always be fine.
Ian
Russ Cox <r...@golang.org> writes:libgcc.a is under a GPL+exception license. Copying it and maintaining
> Where is libgcc.a? What is in it? What is its license?
> Can we just copy it into runtime/cgo.a and be done with it?
the copy would be a pain because it is built in a funny way.
__chkstk is always statically linked because it is called in a special
way that preserves the argument registers. Dynamically link it might
cause the dynamic call to clobber those registers, which would of course
break the program.
Something doesn't add up... Is there a mismatch between the function
and object name (too many underscores)?
-joe
Where is libgcc.a? What is in it? What is its license?
Can we just copy it into runtime/cgo.a and be done with it?
Would making mingw gcc link against the msvc libraries (I know it's
possible) instead of its own help?
possible) instead of its own help?Would making mingw gcc link against the msvc libraries (I know it's
Linking mingw-built C programs against msvcrt.dll isn't a problem, but
like you said, libgcc would be required if gcc extensions (built-ins)
were used.
To compile an executable it's just: gcc test.c -nostdlib -lmsvcrt -o test.exe
But I think main has to be named _main, it's been a while.
> Thanks for the clarification. Is there any other functions in libgcc.a that
> is
> special?
I wouldn't be surprised but I don't know of any others.
Ian
FYI
cgo/test passes when including msvcrt with the CL
http://codereview.appspot.com/5786043/
a = append(a, "-lmsvcrt", "-mno-stack-arg-probe", "-fno-stack-check",
"-fno-stack-protector")
-joe
I played around with this for several hours, changed some code, and
managed to get mingw-gcc-msvcrt working for about 60% of what I
compiled. :( O well.
http://codereview.appspot.com/5786043/cgo/test passes when including msvcrt with the CL
a = append(a, "-lmsvcrt", "-mno-stack-arg-probe", "-fno-stack-check",
"-fno-stack-protector")
like you said, libgcc would be required if gcc extensions (built-ins)Linking mingw-built C programs against msvcrt.dll isn't a problem, but
were used.
I realized after I posted that cgo/test passed with just the CL applied.
Being able to use the msvcrt dll on a windows machine rather then
having to include mingw-gcc libs would be nice but it's not worth the
trouble at this point, nor does it solve the existing problem. I
didn't quite understand what was happening until I started
experimenting, sorry for all the previous noise.
-joe