Conditional Compilation in Go

I am trying to write a Go wrapper using CGo for ENet .

When I tried to compile my wrapper on a Mac, the library was older and had a slightly different interface. 99% of the code is the same thing you need to do for just a few C calls.

What is the best practice to solve such a problem in Go?
Is there a way to do conditional compilation or conditional import?

+6
source share
2 answers

Go has no conditional compilation or conditional import. Handle Type Differences in C Code.

Are [Go] authors created against preprocessing?

+1
source

Separate the contents of a particular platform into a separate file, for example. stuff.go

Now replace stuff.go with versions for different platforms, for example stuff_darwin.go (for Mac), stuff_windows.go, stuff_linux.go, etc.

If the file has this suffix, the go command will compile it only on the specified platform.

+14
source

Source: https://habr.com/ru/post/918681/


All Articles