On Tue, Jan 21, 2020 at 5:24 AM Graham Nicholls <nicholls.gra...@gmail.com> wrote: > > I have the following code: > > 3 /* > 4 selinux.go - return the sestatus > 5 > 6 > 7 The lines below are preamble to the import of "C" - > 8 they should be left untouched > 9 */ > 10 > 11 // //cgo linux CFLAGS: -Iinclude -I. > 12 // #cgo pkg-config: libselinux > 13 // #include <selinux/selinux.h> > 14 // #include <selinux/label.h> > 15 // #include <stdlib.h> > 16 // #include <stdio.h> > 17 // #include <sys/types.h> > 18 // #include <sys/stat.h> > 19 > 20 import "C" > 21 import ( > 22 "fmt" > 23 "net/http" > 24 ) > 25 > 26 const ( > 27 Enforcing = 1 > 28 Permissive = 0 > 29 Disabled = -1 > 30 ) > 31 > 32 func init() { > 33 if len(testFunctionsMap) == 0 { > 34 testFunctionsMap = make(funcPtrMap) > 35 } > 36 testFunctionsMap["selinux"] = SELinuxStatus > 37 initCtr++ > 38 } > > The program also has several other files all in package main. The init > functions in those files do get called; this init function doesn't - > "selinux" never gets added to the testFunctionsMap. > > This used to work - I think on 1.9 was the previous version. I've looked at > the release notes, and it seems that work has been done on cgo - but I can't > see anything which might explain this behaviour.
It's odd that you have a blank line on line 19. That makes all those directives ineffective. The cgo comment must immediately precede the import "C", with no blank lines. Is this really the exact file that you are compiling? The other thing to consider is that if cgo is not enabled, then the go tool will silently not build any Go files that import "C". And cgo is not enabled by default when cross-compiling. Try setting CGO_ENABLED=1 in the environment. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUU5f2HU7ZWxk9xtzLOGwoL5_DLS2m1jdLhDoDip6Ddtg%40mail.gmail.com.