veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.22k stars 223 forks source link

exec: "FR": executable not found in %PATH% #317

Closed an0rak-dev closed 6 years ago

an0rak-dev commented 6 years ago

Hi ! Thanks for your library, it's really a good job :)

I faced an issue when doing a go get -v github.com/veandco/go-sdl2/sdl :

# github.com/veandco/go-sdl2/sdl
exec: "FR": executable not found in %PATH%

My configuration is :

The MinGW bin directories are added to my PATH.

When I run a go build -v -work -x -n, I can see that the library use cgo, which in turn call the C compilation command, by using FR instead of gcc.

FR -I "C:\\Users\\me\\Documents\\Projects\\src\\github.com\\veandco\\go-sdl2\\sdl" -m64 -mthreads ...

As a workaround, I create a copy of my gcc.exe file in theMinGW\bin directory, and rename it FR.exe (ugly, but do the job).

I'm still analysing why the cgo executable will change the executable's name, but if you have an info about this, I'm interested :)

veeableful commented 6 years ago

Hmm strange. Does it also do that when compiling a simple cgo program? Perhaps you can try go run on this snippet and see if it does the same thing.

package main

/*
static int twice(int x)
{
        return x * 2;
}
*/
import "C"

func main() {
        x := C.twice(2)
        println(x)
}
malashin commented 6 years ago

@s-nieuwlandt-dev Can you please run this commands in your windows console and see if it returns FR?

echo %CC%
echo %GCC%

This is how compiler used by cgo is set. It basically takes one from CC or GCC if they are set or defaults to "gcc".

// gccBaseCmd returns the start of the compiler command line.
// It uses $CC if set, or else $GCC, or else the compiler recorded
// during the initial build as defaultCC.
// defaultCC is defined in zdefaultcc.go, written by cmd/dist.
func (p *Package) gccBaseCmd() []string {
    // Use $CC if set, since that's what the build uses.
    if ret := strings.Fields(os.Getenv("CC")); len(ret) > 0 {
        return ret
    }
    // Try $GCC if set, since that's what we used to use.
    if ret := strings.Fields(os.Getenv("GCC")); len(ret) > 0 {
        return ret
    }
    return strings.Fields(defaultCC(goos, goarch))
}

func defaultCC(goos, goarch string) string {
    switch goos+`/`+goarch {
    }
    return "gcc"
}

So you either have environment variable set for CC or GCC, or something else (console) replaces "gcc" to "FR" with alias after that.

an0rak-dev commented 6 years ago

Hi !

Thanks for your answers :)

I can reproduce the error on the snippet, and effectively, my %CC% var is set to FR (which is strange because I tried the same install on a different windows10_64bits computer, and was unable to reproduce this behavior).

So clearly this is not a go-sdl2 issue :)

Thanks for the informations and your time !