@@ -999,13 +999,22 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha
999
999
1000
1000
// Install header for cgo in c-archive and c-shared modes.
1001
1001
if p .usesCgo () && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared" ) {
1002
+ hdrTarget := a .target [:len (a .target )- len (filepath .Ext (a .target ))] + ".h"
1003
+ if buildContext .Compiler == "gccgo" {
1004
+ // For the header file, remove the "lib"
1005
+ // added by go/build, so we generate pkg.h
1006
+ // rather than libpkg.h.
1007
+ dir , file := filepath .Split (hdrTarget )
1008
+ file = strings .TrimPrefix (file , "lib" )
1009
+ hdrTarget = filepath .Join (dir , file )
1010
+ }
1002
1011
ah := & action {
1003
1012
p : a .p ,
1004
1013
deps : []* action {a .deps [0 ]},
1005
1014
f : (* builder ).installHeader ,
1006
1015
pkgdir : a .pkgdir ,
1007
1016
objdir : a .objdir ,
1008
- target : a . target [: len ( a . target ) - len ( filepath . Ext ( a . target ))] + ".h" ,
1017
+ target : hdrTarget ,
1009
1018
}
1010
1019
a .deps = append (a .deps , ah )
1011
1020
}
@@ -2722,7 +2731,7 @@ func (tools gccgoToolchain) ld(b *builder, root *action, out string, allactions
2722
2731
out = out + ".o"
2723
2732
2724
2733
case "c-shared" :
2725
- ldflags = append (ldflags , "-shared" , "-nostdlib" , "-Wl,--whole-archive" , "-lgolibbegin" , "-Wl,--no-whole-archive" , "-lgo" , "-lgcc_s" , "-lgcc" )
2734
+ ldflags = append (ldflags , "-shared" , "-nostdlib" , "-Wl,--whole-archive" , "-lgolibbegin" , "-Wl,--no-whole-archive" , "-lgo" , "-lgcc_s" , "-lgcc" , "-lc" , "-lgcc" )
2726
2735
2727
2736
default :
2728
2737
fatalf ("-buildmode=%s not supported for gccgo" , ldBuildmode )
0 commit comments