how to make a package go-gettable for both inux and Windows?

447 views
Skip to first unread message

Peter Kleiweg

unread,
Oct 15, 2012, 7:52:51 AM10/15/12
to golan...@googlegroups.com

I have this package that installs fine on Linux.
But when I try to install it on Windows, it won't build:

X:\>go get github.com/pebbe/isterminal
# github.com/pebbe/isterminal
C:\Go\src\pkg\github.com\pebbe\isterminal\isterminal.go:24: undefined: syscall.Termios
C:\Go\src\pkg\github.com\pebbe\isterminal\isterminal.go:25: undefined: syscall.SYS_IOCTL
C:\Go\src\pkg\github.com\pebbe\isterminal\isterminal.go:26: undefined: syscall.TCGETS
C:\Go\src\pkg\github.com\pebbe\isterminal\isterminal.go:26: not enough arguments in call to syscall.Syscall6

X:\>

So, what I need to do is change the package to have it use Linux
methods on Linux, and Windows methods on Windows, and in the
package, have a check for what platform it is runing on. But how
can I do that if it won't even build on both platforms?

I could have two separate packages, one for Linux, one for
Windows, but then I would also need two version for all packages
dependent on this package.

How do I solve this?


--
Peter Kleiweg
my Go programming cookbook: http://www.let.rug.nl/~kleiweg/go/

Dave Cheney

unread,
Oct 15, 2012, 8:03:02 AM10/15/12
to Peter Kleiweg, golan...@googlegroups.com
Have a look at the source for the net package. Look at the names of
the files, and the contents of the // +build tags at the top of the
files.

More information is in the "Build Constraints" section of
http://golang.org/pkg/go/build/

Cheers

Dave
> --
>
>

Peter Kleiweg

unread,
Oct 15, 2012, 9:34:49 AM10/15/12
to golan...@googlegroups.com
Dave Cheney schreef op de 15e dag van de wijnmaand van het jaar 2012:

> Have a look at the source for the net package. Look at the names of
> the files, and the contents of the // +build tags at the top of the
> files.

Thanks!
Reply all
Reply to author
Forward
0 new messages