build google/gxui samples error on mac - go

I git clone code from github.com/google/gxui
and then
cd samples/hello_word
GOOS=windows go build
an error occurred
it says
/d01/gopath/src/github.com/goxjs/gl/gl_opengl.go:10:2: no buildable Go
source files in /d01/gopath/src/github.com/go-gl/gl/v2.1/gl
/d01/gopath/src/github.com/goxjs/glfw/desktop.go:10:2: no buildable Go
source files in /d01/gopath/src/github.com/go-gl/glfw/v3.2/glfw
I try to
go get -u github.com/go-gl/gl/v2.1/gl go get -u
github.com/go-gl/glfw/v3.2/glfw
no error occurred
I try to run again
GOOS=windows go build
The problem has not been solved

This could be happening because of your mac doesn't have a c compiler that can cross compiler to the target OS. I tried it on a Linux OS and it compiles without any issues. there was an issue on git about it last year and it's still open till today. I would suggest compiling it directly on the target OS. If you look throught the code in
github.com/go-gl/gl/v2.1/gl/conversions.go
you will notice that it import "c" meaing it will require a C compiler that is compartible with the target OS.

Related

ninja: error: loading 'build.ninja': The system cannot find the file specified. when build hello world in Visual studio

I have followed esp-idf guideline to install and test to build the hello world and blink sample code but both the code met this problem.
Visual studio try to build hello world
> Executing task: ninja <
ninja: error: loading 'build.ninja': The system cannot find the file specified.
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command ninja " terminated with exit code: 1.
I have tested all the ways I can find to fix it but I'm not sure anything I missed or not.
This is one of the way that I test but also met some problem.
cmd try to run the command below
C:\Espressif\frameworks\esp-idf-v4.4>python -m pip install --user -r %IDF_PATH%/requirements.txt
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
This possible problem is the python environment is exist so I cannot do this command, but I try many ways to disabled or deactivated it still cannot.
python path
system environment
After trying to debug this for a long time, I made a backup copy of the entire project folder, then just went hog-wild deleting files. I deleted almost every file I didn't author. Only left the main/CMakeLists.txt, main/component.mk, main/main.c, main/main.h, .gitignore, CMakeLists.txt, and Makefile. Then I ran idf.py set-target esp32 and idf.py -p /dev/ttyACM0 flash monitor and it worked fine again.
VS Code & ESP-IDF on Ubuntu 20.04.05 LTS
Check if the compiler is properly selected. If you don't select a proper c/c++ compiler, then you might get this error. I had mingw in my system, but vs code did not auto detect the compiler. Then I manually added mingw and selected it for compilation after which this issue was resolved.
What worked for me after updating to the new stable release (v5.0) was
Go to the folder S:\esp\esp-idf\esp-idf-v5.0
Run command prompt at this directory and execute install.bat and later export.bat
After trying to build the program in VSCode the error "ninja: error: loading 'build.ninja'" shows up.
Update the path in the ESP-IDF extension in VSCode using ESP-IDF:Configure Paths
locate your project folder e.g. "V:\simpleTest_using_EspIDF_v5_0"
Open command prompt and execute: idf.py build
Now it builds also in VSCode using the Espressif IDF extension.
You not have a build.ninja file. Find this file on proje

unable to cross compile from OSX to Linux

When I try to cross compile my golang project from OSX to Linux, then I get following error message:
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed
and the compilation aborts.
This is how I try to build my application:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build
I also tried using gox:
gox -os="linux"
but it still did not work.
Everything works as expected if I do not use the GOOS=linux tag and I am able to build/run my project for/on my OSX machine successfully.
I can confirm that the command
$env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v main.go
works perfectly fine with a "Hello World" main.go file on MacOS X High Sierra without installing anything else than just go (see also here).
As already pointed out in the comments, you are probably trying to compile with cgo and obviously lack parts of the tool chain and/or headers and that is why your linker throws an error. Please provide an acceptable example, otherwise we won't be able to help you.
You need to install a proper toolchain to do that.
In order to build binaries for architectures different that your build
host, you need far more than just a cross-compiler - you need a
full-blown toolchain, which can be a real pain to create, as you
probably discovered.
A couple of approaches:
Use a proper Linux distribution in a virtual machine, such as
VirtualBox. If you only want to build binaries for Linux/i386 on an
MacOSX/x86_64 host, this is - in my opinion - the easiest, safest and
most clean solution. It is not a cross-compiler, of course, but it
works and it has the added advantage that you can actually test your
executables.
Use a script such crosstool-NG (a descendant of the original
crosstool) to automatically build the toolchain - definitely easier
than building it on your own, although you may have to compromise for
slightly older compiler versions.
Cross compiler for linux on mac os x

golang compiler error: can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go

I am attempting to compile a go program. The code is a small x11 window manager, found HERE. (The code is 98 lines, too long to post here)
Here is the command I run, on x86-64 Ubuntu:
GOOS=linux GOARCH=386 go build littlewm.go
This command works fine on other files in the same directory. However, when I try to compile this one, I get the following error:
can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go
This does not involve the gopath variable, as I have successfully compiled other programs in the same directory. I have a suspicion it involves the code itself or some option I am lacking. As such, this is not really a duplicate of an existing question and is quite possibly unique, since I am not getting the answer I want from other similar questions. Any help is appreciated greatly.
Thanks!
I encountered a similar problem when trying to build my own go program.
I had just added GCO to interface with some native C code in a library.
It built for me for the native platform (the machine I was coding on), but not when I tried to target another platform (using GOOS and GOARCH as you're doing).
Setting CGO_ENABLED to 1 (as mentioned in david's comment) fixed the problem for me:
CGO_ENABLED=1 GOOS=linux GOARCH=386 go build littlewm.go
I was using a makefile to build for multiple platforms using multiple rules, so for me, I put
export CGO_ENABLED = 1
near the top of my makefile so that I didn't need to specify it for each platform.

C source files not allowed when not using cgo or SWIG

I am using Go 1.6 on OSX 10.11.4 and trying to cross compile my go program for windows and linux. I use a library (https://github.com/pebbe/zmq4) in my go program which is a Go binding for a C based implementation. I followed the instructions to cross compile for x86 windows as listed here by issuing the following command:
env GOOS=windows GOARCH=386 go build -v znode.go
However the above command gives me the following error
znode.go:15:2: C source files not allowed when not using cgo or SWIG: dummy.c
Is there a workaround for this? I saw other posts on stackoverflow which suggest moving to go1.5 but i am already on go1.6
FWIW after six years ... user720694's comment has the clue. If there are any .c or .cpp/cc/etc. files in the build directory, adding CGO_ENABLED=0 before go build does the trick.

go tool: no such tool "compile"

I recently started trying go to program some web based applications. At first, everything went fine, until I wanted to cross compile a binary for a different platform. I'm running MacOS and I wanted to compile a binary for linux, so I changed GOOS to linux and GOARCH to amd64. Since then, I always get the error message
go tool: no such tool "compile"
I'm using GoClipse, but running the compile manually by
go install hello.go
I get the same error. When changing back to compiling for darwin architecture, I get the same error now, so basically I'm totally unable to compile any code written in Go at the moment.
I installed it via the binary packages provided by google. In the end I actually got it back to work by just reinstalling it. Sometimes I'm just blind to the easy solution.
After that, I succeeded in cross compiling for linux machine after compiling the necessary cross-compilers by running env GOOS=linux GOARCH=arm GOROOT_BOOTSTRAP=/usr/local/go ./make.bash --no-clean from the Go sources directory.
Thanks for all you efforts, sorry to have kept you busy on such a simple matter.
You have the wrong x64 or x386 package installed most likely. I had 32 installed running 64 bit. Reinstall fixed. Good luck.
You might be able to get away with that if you install Go 1.5, however if you use anything that depends on cgo, you will have to install a cross-compiler linker or install Linux on a virtual machine to be able to cross compile for Linux.
In my case is due to the fact that GOPATH and GOROOT are not set correctly, maybe you can check go env. Here is a discussion may be useful.
The way I figured-out what file is read and caused Go to look for the compile binary in the wrong place can be solved using:
$ strace go tool -n compile 2>&1 |grep openat
openat(AT_FDCWD, "/home/nwaizer/.config/go/env", O_RDONLY|O_CLOEXEC) = 3
In that file, the IDE Goland, add a path to some project, causing the havoc.

Resources