#CGO Cross Platfrom Building
81 messages · Page 1 of 1 (latest)
e.g. if you have //go:build cgo && linux in one, you need //go:build !(cgo && linux) in the other
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
your formula isn't quite correct there, the negation of windows && 386 is !windows || !386
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
i'm not sure how you arrived at !windows && 386
I want to build it for windows and the 386 architecture
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
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
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
in what sense does it not work? what did you try and what did you see?
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
what command are you running to build it?
try removing main.go from those commands
when you name a list of files, the go tool ignores build constraints
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)
what happens when you build at the command line, like it says?
for windows or linux?
^
same issue
linux is trying to use the windows golang file
maybe this https://stackoverflow.com/a/69940448?
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.
errors from the ide won't be helpful here, because it is very difficult for an ide to tell what code to process when build tags are involved
alright it seems like go thinks the build declaration is broken even though it isnt
in what sense?
its respecting it when building for windows but when I build for linux it defaults to the windows build declaration
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 
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
what did you do when you got that message?
the same thing
i just changed my build declaration to
//go:build linux
// +build linux
where is your go:build line within the file?
wym?
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
yes
idek
this is so fucked
it should work
but it isnt
ok so
it works for linux
and not windows now lol
what did you change?
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
without seeing the whole situation, i'm out of ideas
me to