0

I created very simple application that put to output some text.

My development environment is Windows + Docker for Windows. I created ubuntu container and after build my application in Windows for ubuntu

set GOARCH=amd64
set GOOS=linux
go build -o "myapp"

Then I copy 'myapp' file to shared folder and see it in shared folder of my container. After I try to run it inside container but there is an error

enter image description here

Why can't I run it? Was it built incorrectly or do I try to execute it in some wrong way?

In windows I have this output when I run my exe file and I want something the same in Ubuntu.

enter image description here

UPDATE As suggested I try ./myapp and there is Exec format error

enter image description here

Vitalii
  • 10,091
  • 18
  • 83
  • 151
  • 2
    did you try ? `./myapp` – ymonad Feb 09 '17 at 08:15
  • You wrote where you copy the result *to*, but not *from where* you take it. The build command uses another target directory than the install command. – Wolf Feb 09 '17 at 08:48
  • I took the result from src/myProject folder after run build. New file appeared there and I copied it to container – Vitalii Feb 09 '17 at 08:52

1 Answers1

1

On ubuntu and other linux systems, just myapp will try to find myapp from the PATH environment variable. To look specifically for an executable inside the current directory, you need to use:

./myapp

Or use the complete path:

/__shared/myapp

UPDATE: for this to work, your file need to be executable. You can verify it using ls -l:

ls -l
-rwxrwxr-x  1 user user    0 Feb  9 09:45 myapp

If you don't see at least one 'x' in the first column, you need to run:

chmod +x myapp

See understanding-linux-file-permissions for more information on the subject.

UPDATE: the error cannot execute binary file: Exec format error' could come from:

  • a mismatch between the system architecture and the file --> ensure your ubuntu machine is a 64-bit version and compare the output of uname -a and file myapp
  • according to this thread, running a file inside the shared folder of the VM (with windows host) can cause trouble --> try to copy myapp outside the shared folder
Community
  • 1
  • 1
Derlin
  • 9,572
  • 2
  • 32
  • 53
  • 1
    It's better, after I call as you said I have './myapp: cannot execute binary file: Exec format error' :) So there is another problem – Vitalii Feb 09 '17 at 08:34
  • updated the answer, tell me if this resolves your problem. – Derlin Feb 09 '17 at 08:48
  • It seems that it is executable. >> root@7dd1655ae5db:/__shared# ls -l >> total 1764 >> -rwxr-xr-x 1 root root 1804288 Feb 9 2017 myapp – Vitalii Feb 09 '17 at 08:54
  • Simple test showed that it is not the shared folder problem :) I try to run 'file myapp' command and see that 'bash: file: command not found'. Could you tell me if I need to install something to use this command or maybe there is some other one :) Anyway thanks a lot! – Vitalii Feb 09 '17 at 09:22
  • bash in usually under `/bin/bash`. try `echo $PATH`. If it is empty, use `export PATH=/bin/bash` and try again. For this kind of problem, I suggest searching on google first and maybe post another question if you can't figure it out by yourself. Can we consider this question answered ? – Derlin Feb 09 '17 at 09:31