Yes, probably. Please do file an issue on github, thanks. -s
sent from my droid On Jul 30, 2016 4:33 AM, <sat...@aporeto.com> wrote: > Hi Sebastien, > > Thanks for the response but this does not work completely. The issue is > demonstrated in a package here: > > github.com/satyamsi/cbuilds/a > > One file a.go build for linux and has an import "C" - this works fine. > > On non-linux, a_non_linux.go gets used. As this file doesnt use anything C > related, I dont have an "import "C"". In addition the c file has what you > suggested. However, the error says I have to use > "cgo". I used the workaround to add an import "C" and that seems to do the > trick to avoid this error. > > The problem is that the error is thrown just by checking that one is not > using cgo but directory has c files. I think it should do a little more > than that. > > Satyam > > > On Friday, July 29, 2016 at 12:41:18 AM UTC-7, Sebastien Binet wrote: >> >> Satyam, >> >> On Fri, Jul 29, 2016 at 3:25 AM, <sat...@aporeto.com> wrote: >> >>> Hi Folks, >>> >>> If I need to compile c files in a package conditionally based on the OS >>> that I am running on, seems like +build is the right way to do it. I can >>> have two versions of the file: >>> >>> somefile_linux.go which has // +build linux and also an import "C" >>> >>> and >>> >>> somefile_nonlinux.go which has // +build !linux and no importing of "C" >>> >>> In addition, I have file >>> >>> some_cfile.c >>> >>> However, I hit an issue that there is a hard check in the pkg.go which >>> is throwing an error: >>> >>> >>> // The gc toolchain only permits C source files with cgo. >>> if len(p.CFiles) > 0 && !p.usesCgo() && !p.usesSwig() && >>> buildContext.Compiler == "gc" { >>> p.Error = &PackageError{ >>> ImportStack: stk.copy(), >>> Err: fmt.Sprintf("C source files not allowed when not using cgo >>> or SWIG: %s", strings.Join(p.CFiles, " ")), >>> } >>> return p >>> } >>> >>> >>> Well if the go file being compiled doesnt need any c files, why is "gc" >>> even trying to see the c files ? >>> >>> How do I achieve my intent ? >>> >> >> IIRC, you can use the same build tags syntax in C/C++ files than in your >> Go files. >> >> Just put, e.g., >> // +build !linux >> >> as the first line of your C/C++ file. >> >> hth, >> -s >> >> -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.