1

To outline my end goal. I want to compile a go application, statically linking to QT5. I have statically compiled QT5. Now I need to compile my Go program.

As I understand it to do this, I have to use gccgo rather than the gc compiler. Fine.

So first I have to install the gccgo compiler, which is gcc with the go language enabled in config.

I have followed this: https://golang.org/doc/install/gccgo

and this seperately: https://solarianprogrammer.com/2016/05/10/compiling-gcc-6-mac-os-x/

to see if I could use a newer version of GCC. However in both cases I receive:

checking for isl 0.16, 0.15, or deprecated 0.14... yes
checking for isl 0.16 or 0.15... yes
configure: error:
The following requested languages could not be built: go
Supported languages are: c,c,c++,fortran,jit,lto,objc,obj-c++

when I run configure before make and make install

So apparently GCC doesn't know about Go even though the Go documentation says this is how to do it?

Anyone got any reliable source for doing this?

amlwwalker
  • 3,161
  • 4
  • 26
  • 47
  • As far as I know, gccgo isn't supported on darwin. Why do you need gccgo? – JimB Jan 20 '17 at 14:36
  • I want to compile statically with QT as part of the binary. Apparently to do that you have to set the compiler to gccgo. First I statically compiled Qt and then tried something like: `CGO_ENABLED=1 go build -a --ldflags '-extldflags "-static -L/Users/alex/Qt/5.7.0_static_osx/lib"'` but that gives: `clang: error: ld: library not found for -lcrt0.o`. When i add `-compiler gccgo` I get `fork/exec : no such file or directory` which apparently means gccgo is not installed – amlwwalker Jan 20 '17 at 15:40
  • You don't need gccgo to do static linking, and it's probably easier not to use it. You do however need to properly list all the libraries to link in the ldflags. It's usually easier to do this in the cgo comments in your source rather than use `-ldflags -extldflags...` – JimB Jan 20 '17 at 15:46
  • 1
    Do you know of an example of this. Its my first time static linking, any resource would be appreciated? – amlwwalker Jan 20 '17 at 15:47
  • I tried: `CGO_ENABLED=0 go build -a -installsuffix cgo` with `// #cgo LDFLAGS: -L/Users/alex/Qt/5.7.0_static_osx/lib -lgb` at the top of `main.go` and I get: `undefined: qml.Object`, `undefined: qml.Window` – amlwwalker Jan 20 '17 at 15:53
  • You're using cgo, you can't set `CGO_ENABLED=0` – JimB Jan 20 '17 at 16:04
  • Hmmm, the problem is `panic: runtime error: cgo argument has Go pointer to Go pointer` - for the qml libraries cgo must be disabled? `CGO_ENABLED=1 go build -a -installsuffix cgo` `// #cgo LDFLAGS: -static -L/Users/alex/Qt/5.7.0_static_osx/lib -lgb` – amlwwalker Jan 20 '17 at 16:08
  • If you disable cgo, you can't link to the qml libraries. That error is because you're code or qml is dong something incorrect in cgo. A quick glance over at the repo looks like it may not be maintained any longer, not sure if this is a package you want to depend on. – JimB Jan 20 '17 at 16:21
  • Sounds like its a problem then. I wonder if there is a new qml library for go. I'll try and find one. Thanks – amlwwalker Jan 20 '17 at 16:25
  • For anyone looking at this I have had luck with: github.com/SjB/qml and checking out the `go1.6-port` branch. Then import the above. JimB, so the above now runs with the forked library, it also builds but `otool -L` says the libraries are still dynamically linked, how do I tell it to link them in statically? – amlwwalker Jan 20 '17 at 17:42

0 Answers0