#CGO Cross Platfrom Building

81 messages · Page 1 of 1 (latest)

maiden jetty
#

both halves need build tags such that they mutually exclude each other

#

e.g. if you have //go:build cgo && linux in one, you need //go:build !(cgo && linux) in the other

narrow delta
#

So my first file has the declaration //go:build windows && 386 // +build windows,386 and my second is //go:build !windows && !386 // +build !windows,!386

#

id change it to

maiden jetty
#

your formula isn't quite correct there, the negation of windows && 386 is !windows || !386

narrow delta
#

so it should be like ```
//go:build !windows && 386
// +build !windows,386

#

?

#

I did that before and Got the error ```
build constraints exclude all Go files in

maiden jetty
#

i'm not sure how you arrived at !windows && 386

narrow delta
#

I want to build it for windows and the 386 architecture

maiden jetty
#

that would be what windows && 386 does

#

you need something which matches everything else where you want to compile

#

i.e. the logical negation of that

narrow delta
#

so ```//go:build !(windows && 386)
// +build !windows !386

#

?

maiden jetty
#

with go:build, you can just put !(...) around everything and not worry about it, or you can apply de morgan's laws to negate each term respectively

#

that should work, yes

narrow delta
#

it still doesnt work

#

the file i want to build has the declaration ```
//go:build windows && 386
// +build windows,386

#

the file that I want to be build if the os is not windows and the architecture is not 386 is ```
//go:build !(windows && 386)
// +build !windows !386

maiden jetty
#

in what sense does it not work? what did you try and what did you see?

narrow delta
#

when I build it for linux i get ```
xxxxx.c:1:10: fatal error: windows.h: No such file or directory

#

its trying to compile the c code instead of giving me the error build constraints exclude all Go files in

maiden jetty
#

what command are you running to build it?

narrow delta
#

thats why this doensnt make any sense l

#

lol

maiden jetty
#

try removing main.go from those commands

#

when you name a list of files, the go tool ignores build constraints

narrow delta
#

for the linux file my ide is giving me the error go list failed to return CompiledGoFiles. This may indicate failure to perform cgo processing; try building at the command line. See https://golang.org/issue/38990.

#

for the first declaration //go:build !(windows && 386)

maiden jetty
#

what happens when you build at the command line, like it says?

narrow delta
#

for windows or linux?

maiden jetty
#

either

#

both, really

narrow delta
#

windows works perfectly

#

linux I get

narrow delta
#

same issue

#

linux is trying to use the windows golang file

maiden jetty
#

if your go:build line is properly located, then it will prevent that. so, the conclusion is either your go:build line is not properly located, or else another file in the package is using the windows cgo.

maiden jetty
narrow delta
#

alright it seems like go thinks the build declaration is broken even though it isnt

maiden jetty
#

in what sense?

narrow delta
#

its respecting it when building for windows but when I build for linux it defaults to the windows build declaration

maiden jetty
#

i don't think that is what is happening

#

if build tags weren't properly being set with respect to GOOS, the go issue tracker would be very active sunturtle

narrow delta
#

xD true

#

lol

#

im getting the error C source files not allowed when not using cgo or SWIG: now

#

doesnt make any sense

#

i have it enabled

maiden jetty
#

what did you do when you got that message?

narrow delta
#

the same thing

#

i just changed my build declaration to

#
//go:build linux
// +build linux

maiden jetty
#

where is your go:build line within the file?

narrow delta
#

wym?

maiden jetty
#

it has to come before the package statement in the file

#

considering you're seeing different behavior when you change it, i don't think that's the difference, but it's worth double checking

narrow delta
#

heres my full thing

#

at least for linux

#

that looks correct right?

maiden jetty
#

yes

narrow delta
#

idek

#

this is so fucked

#

it should work

#

but it isnt

#

ok so

#

it works for linux

#

and not windows now lol

maiden jetty
#

what did you change?

narrow delta
#

i moved the c files into a directory

#

but the thing is

#

not

#

now*

#

cgo cant find the c files so it doesnt compile for windows

#

lol

#

im trying to include it by using

maiden jetty
#

without seeing the whole situation, i'm out of ideas

narrow delta
#

me to