Build constraints ignored cross compiling for windows.

492 views
Skip to first unread message

pe...@scraperwiki.com

unread,
May 21, 2014, 1:57:16 PM5/21/14
to golan...@googlegroups.com
Hi All,

I'm trying to cross compile for Windows64 from Linux64. I have specified +build constraints. However, when compiling for windows it looks inside the unix.go file, even if I specify // +build !windows and gives me `unknown field in syscall.SysProcAttr` and redefined functions. What am I missing?

Code to reproduce below.

Thanks in advance,

- Peter

$ go version
go version go1.2.2 linux/amd64
$ git clone https://gist.github.com/anonymous/9ce13a550a1e8f4574f5cd 9ce13a550a1e8f4574f5
$ go build -v
_/home/pwaller/tmp/9ce13a550a1e8f4574f5

$ GOOS=windows go build -v
_/home/pwaller/tmp/9ce13a550a1e8f4574f5
# _/home/pwaller/tmp/9ce13a550a1e8f4574f5
./unix.go:7: unknown syscall.SysProcAttr field 'Setsid' in struct literal
./windows.go:5: Frobnicate redeclared in this block
previous declaration at ./unix.go:6

$ cat main.go
package main

func main() {
println("Hello, world")
}

$ cat unix.go 
// +build linux
package main

import "syscall"

func Frobnicate() {
_ = syscall.SysProcAttr{Setsid: true}
return
}

$ cat windows.go 
// +build windows

package main

func Frobnicate() {
return
}

minux

unread,
May 21, 2014, 7:27:43 PM5/21/14
to pe...@scraperwiki.com, golang-nuts


On May 21, 2014 7:23 PM, <pe...@scraperwiki.com> wrote:
>
> Hi All,
>
> I'm trying to cross compile for Windows64 from Linux64. I have specified +build constraints. However, when compiling for windows it looks inside the unix.go file, even if I specify // +build !windows and gives me `unknown field in syscall.SysProcAttr` and redefined functions. What am I missing?
>
> Code to reproduce below.
>
> Thanks in advance,
>
> - Peter
>
> $ go version
> go version go1.2.2 linux/amd64
> $ git clone https://gist.github.com/anonymous/9ce13a550a1e8f4574f5; cd 9ce13a550a1e8f4574f5
> $ go build -v
> _/home/pwaller/tmp/9ce13a550a1e8f4574f5
>
> $ GOOS=windows go build -v
> _/home/pwaller/tmp/9ce13a550a1e8f4574f5
> # _/home/pwaller/tmp/9ce13a550a1e8f4574f5
> ./unix.go:7: unknown syscall.SysProcAttr field 'Setsid' in struct literal
> ./windows.go:5: Frobnicate redeclared in this block
> previous declaration at ./unix.go:6
>
> $ cat main.go
> package main
>
> func main() {
> println("Hello, world")
> }
>
> $ cat unix.go 
> // +build linux
> package main

put an empty line after the build tag otherwise it won't take effect (it's treated as part of the package docs)

Jan Mercl

unread,
May 21, 2014, 7:28:13 PM5/21/14
to pe...@scraperwiki.com, golan...@googlegroups.com

There seems to be a missing empty line after the build directive in unix.go.

-j

Carlos Castillo

unread,
May 21, 2014, 10:46:39 PM5/21/14
to golan...@googlegroups.com, pe...@scraperwiki.com
If you run "go vet" on your code, it should tell you what's wrong with you build constraints (among other things).

Peter Waller

unread,
May 22, 2014, 2:56:37 AM5/22/14
to golan...@googlegroups.com
Thanks guys, that was it!
Reply all
Reply to author
Forward
0 new messages