Question about icon and version

Hi,

I want to run a go program in the background,
in addition to attach basic versioninfo and
icon to the executable.

Building the executable works fine,

go build -ldflags="-H windowsgui"

However, if I run

go generate

(to create a resource.syso file) and then run

go build -ldflags="-H windowsgui"

, the following error appears:

C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64
-w64-mingw32/bin/ld.exe: i386 architecture of input file `C:\Users\ladm
AppData\Local\Temp\go-link-291640663\000000.o’ is incompatible with i386
:x86-64 output collect2.exe: error: ld returned 1 exit status

Below is a code snippet I use to demonstrate the issue. I am unsure my problem is related to the
imported stuff, my architecture
(trying GOARCH=386 results in an error:
undefined: inputhook.HookKeyboard) or
if it is the way I generate/build the executable.

I am very grateful for any guidance on the matter.

Code:

//go:generate goversioninfo -icon=flogo.ico
package main

import (
“fmt”
github.com/vence722/inputhook
)

func hookCallback(keyEvent int, keyCode int) {
fmt.Println(“keyEvent:”, keyEvent)
fmt.Println(“keyCode:”, keyCode)
}

func main() {
inputhook.HookKeyboard(hookCallback)
ch := make(chan bool)
<-ch
}

Hi

I have tried to build the same program with the same package, without any problems.
I using: http://tdm-gcc.tdragon.net/download, to install MinGW. I have build with and without goversioninfo.

  1. Have you tried to compile it without goversion?
  2. You got some errors regarding some x86-file in you temp-folder. Have you tried to clean you temp?
  3. You also tries to build it with x86-support, but it complains about a missing inputhook package. Try to build the inputpackage with x86-support before you tries to build.

I see you are using the example-program from inputhook-git-repo. You tries to print out the key-strokes to screen. If you compile the program without the cmd, you will don’t get any output.

Good luck.

Hi, and thanks for your suggestions.

I have tried compilation using TDM-GCC-32 and TDM-GCC-64 from the link you mention without success.

  1. When I compile using

go build file.go

The executable is being built just fine (as expected it does not build icon file nor version info into the executable).

However, if I just run

go build

(after a go generate to generate .syso ang get version/icon embedded) in the directory where file.go is located,
the error message mentioned appears, even if I take away the goversion part.

  1. I have cleaned out the temp folder without any improvement/changes.

  2. How do I build the inputpackage with x86 support?
    I have tried setting GOARCH to 386 and then do a go build, but I guess it is not sufficient?
    At least I then get the error about undefined: inputhook.HookKeyboard

My intention is to check for user activity, not to print on the screen - so I am good about
building it without cmd when all checks out. Reason for it to be there for now is to verify
that the functionality is in place.
However, my goal is to embed the icon file, in addition to having version info built into the file.

Thanks

I had another look, this time using go version 1.9.1 and TDM-GCC-64.
Most likely, the previous errors were related to an incorrect version of the compiler being used.
My windows machine has got multiple compilers, and once I made sure to have the TDM-GCC-64 in the beginning
of the PATH environment variable, all went fine. Icon, version information and a non-cmd executable was built without errors.

go generate
go build -ldflags "-H windowsgui -linkmode=internal"

(and GOARCH=amd64)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.