Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

Issues while compiling a Go app from Windows to Linux

My issue:

I need to compile a Go application from Windows (current workspace) to Linux (deployment environment), I've try several times using few techniques described in this platform and many more and nothing help, everything looks fine but isn't work.

I'm compiling for linux using this script in windows

$ set GOARCH=amd64
$ set GOOS=linux
$ go build app_name.go

in the cmd folder I can find a file named app_name with no extension, which should be fine. Then, I receive an error when trying to execute the binary in Linux, using few ways

$ ./app_name
-bash: ./app_name: Permission denied

$ source app_name
-bash: source: app_name: cannot execute binary file

this is the file that I received after the compilation:

-rw-r--r-- 1 xxx  xxx  7313830 Jan 26 16:59 app_name

If I run the application in windows with go run -arguments app_name.go it works perfect, but the issue appear after compile or try to compile the app for linux, I can't run the app even as root

question from:https://stackoverflow.com/questions/65910721/issues-while-compiling-a-go-app-from-windows-to-linux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On Unix systems, a file must have the executable bit set in order to be able to be run. This is the only way that the system knows what programs or scripts can be run, and differs from Windows, which uses extensions.

In this case, you need to change permissions by running chmod u+x unified_mapper before trying to execute it. If you want other users to execute it as well, you can do something like chmod 755 unified_mapper. Run man 1 chmod in the manual page to see more details about possible invocations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...