Build web app error

I have developed my web application on windows 10 using GoLand IDE, it’s working fine.
now I install GO in openSuse Leap 42.3 and I place my application under the folder /srv/www/htdocs/go/src

My Go version is: go1.7.5 linux/amd64

My GO env is:

GOARCH=“amd64"
GOBIN=”/usr/bin"
GOEXE=""
GOHOSTARCH=“amd64"
GOHOSTOS=“linux"
GOOS=“linux"
GOPATH=”/usr/share/go/1.7/contrib"
GORACE=”“
GOROOT=”/srv/www/htdocs/go"
GOTOOLDIR=”/srv/www/htdocs/go/pkg/tool/linux_amd64"
CC=“gcc"
GOGCCFLAGS=”-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build988831746=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED=“1”

running the command

  • go run main.go
    or
  • go build main.go

will return this error:

runtime

…/runtime/cgo.go:9:3: //go:cgo_export_static main only allowed in cgo-generated code

Please advise

What was the version of go you used on windows?

Do you have the same problem when you cross compile from windows using proper GOOS and GOARCH values? (can go actually crosscompile from win to linux, I’ve only done the other way round so far…)

Also it seems as if you have GOROOT and GOPATH swapped. GOROOT should contain system packages while GOPATH should be developers code.

Do you actually need to use cgo? If not, that’s the first thing I’d get rid of.

thank you for your replies.

I have changed the
GOPATH="/srv/www/htdocs/go"
GOROOT="/srv/www/htdocs/go/bin"

that error not appearing anymore :slightly_smiling_face:

now I’m getting this:

import cycle not allowed
package main
imports crypto/md5
imports crypto
imports hash
imports io
imports errors
imports runtime
imports runtime/internal/atomic
imports unsafe
imports runtime
import cycle not allowed
package main
imports net/http
imports crypto/tls
imports crypto/x509
imports net
imports runtime/cgo
imports runtime/cgo

this is my main.go file header

package main

import (
“fmt”
“log”
“net/http”
“ressources/gorilla/mux”
_ “ressources/gorilla/securecookie”
“database/sql”
_ “ressources/mysql”
"crypto/md5"
“encoding/hex”
“sync”
)

No need

GOROOT=”/usr/share/go/1.7/contrib” probably, not on Linux now.

I already change that one to GOROOT="/srv/www/htdocs/go/bin"

Yes, but that’s wrong, it should be a path where go package is installed and not your project dir.

This looks as if it were even worse than what you had before.

Please do yourself a favor and build the executable locally and only upload the binary to your server. Using either GOs cross compile capabilities or the go-docker-containers should be sufficient.

Or you could build in your home folder on the host. You do not need to put the sources or binary in /srv/www…

In general, I’d not put it into a path thats usually served by the distros favorite webserver. You run the danger of exposing secret stuff on package install or update then.

Just create a service (systemd-unit, upstart, initd, whatever your distro uses) and start it.

1 Like

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