go tool: no such tool "compile" - go

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.

Related

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.

How to build xmlsec on Windows

I am trying to build xmlsec on Windows... I am not an experienced C/C++ developer and not really familiar with the build process if something along the lines of "make ... make install" doesn't do the trick.
xmlsec comes with a Win32 subdirectory, a nice ECMAScript configure.js that takes an optional bunch of parameters and a readme which explains that after running the configure, "nmake ... nmake install" should do the trick. (Obviously it isn't quite that easy or I wouldn't be posting here!)
xmlsec also depends on a number of other libraries (see here for a graphic). I have downloaded the sources for those libraries.
My problem is that I don't know how to arrange those sources, or what to tell the configure.js script, in order to get a build to work.
For instance, the nmake process complains that it can't find "iconv.h" (iconv is one of the required libraries), which is not surprising because there isn't one. Instead there is an "iconv.h.in" and an "iconv.h.build.in"... which I don't know what to do with to produce the required 'iconv.h".
(I am using MS Visual Studio 2010 at the command prompt (which I think is the recommended approach.)
Does anybody out there know how to do this? Any help at all would be very much appreciated.
TIA
Mike Peat
You don't need to build xmlsec, you can directly download the wheel file from this link
https://github.com/mehcode/python-xmlsec/releases
It has all the dependencies installed with it.
have you tried the Msys with Mingw32 compiler? In Msys, you can do make and make install trick. I have successful with Msys in compile xmlsec. If you want to use Msys and have difficulties, I can help.
Anyway, in general, there must be a iconv.h file in the pre-compile folder provided by Zlatkovic (i.e C:\iconv\include\iconv.h). You may want to download again the folder. After figure out where all the dependencies are, put the path in environment path. For your information, I once tried with the configure.js but not successful. Hope that you are luckier than me :D
Hi Kristine (#Kristine T) - (and thanks for getting back to me!)
I had not been doing "make clean", but have now done so ("make clean", followed by "make" - no change in the result though).
The problem I get with the "make" is that it throws an error on compiling "dl.c" saying that "PACKAGE" is undefined (line 295).
I have also had problems using the compiled version of libxml2 - "configure" always says it can't find it (it is there, but...), so I have been using the --with-libxml-src=... parameter to configure, giving it the full source of libxml2 to work with, getting configure to at least finish OK.
I don't have the same problems with openssl or libxslt where I can either tell configure about the compiled version (using --with-XXX={path-to-dir}, or just omit ={path} bit, in which case it seems to find MinGW's own versions, but that doesn't work with libxml2.
Mike

use MinGW to create exe file in windows from GNU source package

the basic idea was, I wanted to generate the call graph in text format for several c files. After googling around for long time, i found cflow, which can deliver everything I want, but it is only runable in Linux or else. Then I began to search how to compile the cflow source files on the web to a exe file. I found MinGW which should be able to do the cross-platform compilation.
After installing the MinGW and the MSYS and running the usual commands "./configure; make; make install", I simply got an error that "mkdir" was not found. Actually. Actually I was wondering whether this is the correct way to compile the whole package.
Does anyone has an idea how I can build the cflow.exe correctly in Windows? If there is a tutorial or something like this, I will be very thankful.
Song
Solution
Please try this Github repository "MinGW + MSYS build of GNU cflow 1.4" (For Windows).
https://github.com/noahp/cflow-mingw
It contains already compiled "cflow.exe",and an instruction about how to build cflow using mingw and msys.
Test
System Environment:Win 8.1 (x64)
1.I tested the "cflow.exe" downloaded from the github repository , and amazingly it worked!
2.I followed the mingw compiling instruction,and it successfully compiled "cflow 1.5".
Command:
bash configure
make
I was able to do that today. I'm using cygwin, after installing gcc, binutils, make and after downloading the gnu cflow.tar.gz, it was as easy as ./configure ; make ; make install.

'Go' windows port build problems: 8l linker crashes

I'm looking to give the 'Go' programming language a try but I'm having trouble getting even a simple test example to work. I think it's probably an issue with the port so I've submitted a ticket under issues in gomingw project page.
What steps will reproduce the problem?
Create any simple go test program
compile it with 8g. ie. 8g hello.go
link it with 8l. ie. 8l hello.8
What is the expected output? What do you see instead?
I expect 8l to link successfully with no errors. Instead I see the follow errors output followed with a crash.
> goos is not known: mingw
> warning: uanble to find runtime.a
> runtime.morestack not defined
What version of the product are you using? On what operating system?
This is on windows 7 with gowin32_2010-12-02.zip
Please provide any additional information below.
I have set the 4 standard go variables on my environment as follows:
goos = mingw, gobin = G:\oss\go\bin, goarch = 386, goroot = G:\oss\go
From looking at the error, I'm going to say it looks like it needs something from mingw gcc toolset? Though I see no mention of this requirement anywhere, neither in the readme or install. What is the runtime.a that is missing? Is it part of mingw? I've also tried one version before this latest one and the problem is present on that version as well.
Has anyone else that's tried Go's port of windows encountered an issue like this? What could be causing this?
Thanks
The reason for the failure is stated in the error message: goos is not known: mingw. Read the instructions for setting the GOOS environment variable. Set GOOS=windows.
You should also be using the latest release of the Go Windows port binary.

Resources