I just started with Go and generally I am new in programming.
I noticed a strange behavior of cmder bash session when I run a compiled to exe Go program.
I put the program into the Windows folder.
It just calculate an md5sum of a text. The command line argument is the text.
When I run the program by cmd or cmder/cmd session it runs as expected.
If I run it by cmder/bash session the system tells me that there is no such file or directory. It takes the argument as a path.
Why is that? I am asking because it’s more convenient for me to use bash syntax.
Sounds like a build architecture problem. As far as I understand:
- the compiled binary is for
windows/amd64
(I’m assuming you’re operating on Windows) -
cmder/bash
should be operating in unix architecture, which also means there are a lot of architecture to choose from. (Suggestlinux/amd64
). -
cmd
is operating on Windows architecture, therefore, the existing binary works.
Try cross-compile into linux/amd64
and use cmder/bash
to find the new binary. You need to export GOARCH=linux/amd64
.
I previously wrote a guide here: https://sites.google.com/view/chewkeanho/guides/go/build. However, I did no have the command line for Windows to cross-compile. You might need to explore a bit.
Keywords: cross-compile, GOARCH
NOTE: I may be wrong since there is limited information available from your question.
I’m not sure if I understand you correctly… What do you mean by “I put the program into the Windows folder”? Are you talking about C:\Windows
here? Please remove it there, thats the OS’ space and shouldn’t be touched by you.
From what you describe otherwise, it seems to be a discrepancy in PATH
between both environments. Usually bash
will inherit the PATH
of the parent environment (windows system in your case), at least if you are using a bash
from a POSIX compatibility layer as cygwin or “git for windows”. You might have overwritten it in the .bashrc
then though.
If though you use the WSL-bash
then it has its own environment and does not inherit from windows at all, as it is a “real” linux and wouldn’t be able to run windows binaries anyway.
These works is more simple on mac or linux. Did you try these platforms?
Even though I’d always prefer Linux over windows or macOS, proposing to use a different operating system is not the solution to the problem at hand.
In fact the problem seems to be that the user doesn’t understand how different tools on their computer work together. This problem can happen on every operating system and is not unique to windows.
let’s wait for OP to supply more information. Otherwise, it’s hard to tell where went wrong.
I’m not quite sure what information to provide. I’m using Windows 10 x64 right now. I am planing to install a Linux system but on a separate hard disk. Which I have to buy. I prefer Linux but have to work on Windows.
I didn’t touch .bashrc or any other configuration. I installed WLS yesterday and I could use that eventually. As soon as I know how to access the computer’s folders and the files.
Quick research gives me that C drive is located in /mnt . So obvious that I even didn’t think about it
Noted, keep in mind that Go program requires you to cross-compile to the deployment OS.
As far as I understand, WLS is a different system. You need to compile to linux/amd64
and give it a try.
I will remember that. Thank you.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.