Create go file for "release"

I want to make a golang file for “release”.
This is my command:

go build -o testi.exe -ldflags "-H windowsgui"

What is the correct way?

Yes. The go compiler always compiles in “release” mode.

I’m sorry if I did not understand your question.

1 Like

I tried the commands:
go build -ldflags “-s” testi.go
size:2.06 MB

go build testi.go
size:4.96 MB

go build -o testi.exe -ldflags "-H windowsgui"
size:4.96 MB

First Command Is Lesser Size. but opens cmd.

my code:

    package main
import (
func main() {
    if err := qml.Run(run); err != nil {
        fmt.Fprintf(os.Stderr, "error: %v\n", err)
func run() error {
    engine := qml.NewEngine()
    engine.On("quit", func() { os.Exit(0) })

    component, err := engine.LoadString("hello.qml", qmlHello)
    if err != nil {
        return err
    window := component.CreateWindow(nil)
    return nil
const qmlHello = `
import QtQuick 2.2
import QtQuick.Controls 1.1
Rectangle {
    id: page
    width: 320; height: 240
    color: "lightgray"
    Text {
        id: helloText
        text: "Hello world!"
        y: 30
        anchors.horizontalCenter: page.horizontalCenter
        font.pointSize: 24; font.bold: true
1 Like

-s is not recommended as it produces broken binaries. In some versions of Go, -s has no effect.

1 Like

I installed :
This command works:
go build -ldflags “-s” testi.go
This amount is not high? “size:4.96 MB”

I don’t think so, 4.96mb for a whole program, including qml seems reasonable.

See also

1 Like

in qt and c++
the program is 25.0 KB for “release” And for debug : 850 KB .
but in go:4.96 MB

Go is not C, or C++. Go programs are generally statically linked and are generally larger than programs which are dynamically linked.


4.96 mb is the correct size for your program.

1 Like

size total program with dll : 743mb
Everything that needs:

my command:
go build -o testi.exe -ldflags “-H windowsgui”

this program Compiled for "debug"

This is as good as it gets. Please review the links I pasted above.

Means:runtime program on any system should be installed?

The runtime package is always linked into each Go program. This accounts for some (not all) of the size of a Go program.

I can not understand what your mean.

What he means is that the way the binaries produced by the Go compiler are structured, they include all the runtime bits and pieces it needs. This is what makes the binaries look large in comparison to other languages.

As for the debug vs non-debug part of your question, I don’t know my way around windows to give you an answer, but perhaps I can nudge you in the right direction. QML uses MinGW to build. In it specifies the Qt libraries it pkg-config to find. If you look at the .pc file for Qt, it’s hard-coded to use the debug libraries. If you edit that file (Qt5Core.pc Qt5Widgets.pc Qt5Quick.pc), you can remove the “d” from the library names.

1 Like

My Problem Is with “release”

If you mean here:
there are not these files at all:
Qt5Cored.pc Qt5Widgetsd.pc Qt5Quickd.pc


I’m sorry you haven’t been able to get the answers you need. It would be valuable if you could take some time to explain the background of the issue you are having. Possibly this form would be useful

I’m trying to describe your desired goal

So far I have tried describe the steps you have tried to achieve this goal

I expected it to do describe what you expected to happen

But instead describe what happened when you tried the steps you outlined above

So far you have mentioned

  • go binaries are larger than C++ binaries
  • you cannot link to the release version of a Qt5 library
  • Visual Studio has the concept of a debug build and a release build, but you are having trouble finding the equivalent in Go.

If these are all questions you have, I recommend starting a new thread for each of them.



Why does it give me this error message?
The program can’t start because Qt5Cored.dll is missing from your computer.
Try reinstalling the program to fix this problem.

I have created release file.
But go file isn’t execute out of workspace dir:

my list dll :

my code: for Qt5Core.pc

Name: Qt5 Core
Description: Qt Core module
Version: 5.5.0
Libs: -L${libdir} -lQt5Core 
Libs.private: -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr .obj\debug\Qt5Cored_resource_res.o -LF:\\qt\\5.5\\mingw492_32/lib -lqtpcred  
Cflags: -I${includedir}/QtCore -I${includedir}

The problem was solved.
I used the following programs:
enter link description here