Report that cgo is required for building for FreeBSD
# golang.zx2c4.com/wireguard/wgctrl
/root/go/pkg/mod/golang.zx2c4.com/wireguard/[email protected]/os_freebsd.go:18:27: undefined: wgfreebsd.New
gmake: *** [Makefile:78: build] Error 1
OS: FreeBSD 14.2-RELEASE
Wireguard kernel module if_wg.ko is loaded.
I only have a Linux machine, but do you have cgo disabled by chance? What happens with:
CGO_ENABLED=1 GOOS=freebsd go build ./...
I'm trying to build https://github.com/h44z/wg-portal
# gmake build
cp scripts/wg-portal.service dist
CGO_ENABLED=0 go build -o dist/wg-portal \
-ldflags "-w -s -extldflags \"-static\" -X 'github.com/h44z/wg-portal/internal/server.Version=-'" \
-tags netgo \
cmd/wg-portal/main.go
# github.com/h44z/wg-portal/internal/lowlevel
internal/lowlevel/netlink.go:57:50: undefined: netlink.FAMILY_V4
internal/lowlevel/netlink.go:62:50: undefined: netlink.FAMILY_V6
internal/lowlevel/netlink.go:99:17: undefined: netlink.RuleAdd
internal/lowlevel/netlink.go:103:17: undefined: netlink.RuleDel
internal/lowlevel/netlink.go:107:17: undefined: netlink.RuleList
# golang.zx2c4.com/wireguard/wgctrl
/root/go/pkg/mod/golang.zx2c4.com/wireguard/[email protected]/os_freebsd.go:18:27: undefined: wgfreebsd.New
gmake: *** [Makefile:78: build] Error 1
cgo being disabled is the problem. The FreeBSD implementation has a hard dependency on cgo at the moment:
package wgfreebsd
// #include <stdlib.h>
// #include <netinet/in.h>
import "C"
// ...
// New creates a new Client and returns whether or not the ioctl interface
// is available.
func New() (*Client, bool, error) {
I can at least try to come up with a shim here that shows a useful compilation error like wgfreebsd.CgoRequiredForFreeBSD not defined.
I changed CGO_ENABLED=1 in Makefile:
# gmake build
cp scripts/wg-portal.service dist
CGO_ENABLED=1 go build -o dist/wg-portal \
-ldflags "-w -s -extldflags \"-static\" -X 'github.com/h44z/wg-portal/internal/server.Version=-'" \
-tags netgo \
cmd/wg-portal/main.go
# github.com/h44z/wg-portal/internal/lowlevel
internal/lowlevel/netlink.go:57:50: undefined: netlink.FAMILY_V4
internal/lowlevel/netlink.go:62:50: undefined: netlink.FAMILY_V6
internal/lowlevel/netlink.go:99:17: undefined: netlink.RuleAdd
internal/lowlevel/netlink.go:103:17: undefined: netlink.RuleDel
internal/lowlevel/netlink.go:107:17: undefined: netlink.RuleList
gmake: *** [Makefile:78: build] Error 1
I can at least try to come up with a shim here that shows a useful compilation error like
It would be helpful. Thank you.
Yep, so you can see now that wgctrl-go is building. But ultimately the wg-portal code is not using build tags correctly and assuming Linux/netlink implementation, so your next problem lies there.
Ok, thank you.
I'll report the problem to wg-portal project.
We can close this issue.
P.S: Thank you for the fast response.
No problem, I'll leave it open for now but edit to make the error more clear.
Is it possible to remove CGO requirement in the future version?