[SOLVED] New to rust - problem running first program


#1

Hi folks, Windows user here. Recently installed 1.0.0 stable and manually added the bin folder to the system path. Typing $ rustc --version in GitBash works as expected.

I’m able to create a rust source file - using the .rs file extension - and compile into an executable by running rustc hello_world.rs (which creates hello_world.exe).

However, I’m not able to run the executable. In GitBash, I receive the error: sh.exe": ./hello_world: Bad file number

In the command window (with and without Administrator rights) , I receive the error: Access is denied.

Running ls -l in GitBash, the access rights are -rwxr-xr-x on the executable.

Any help would be appreciated. Thanks in advance.

Edit: I’m using Windows 8.1 64-bit. Installed rust from: rust-1.0.0-x86_64-pc-windows-gnu.msi


#2

Could you try compiling a program with Rust from cmd.exe and see if the resulting binary can be run that way?

Also, did you install Rust to the default location?


#3

Hi retep998,

Compiling with cmd.exe results in no change (previously, I was using the GitBash command line to compile). It gives me an executable file but an error when I run it “Access is denied.”

I installed Rust to the default location.

Thank you for replying and trying to help me figure this out.


#4

Where are you building the code? Are you in a directory that you own and have full permissions to?


#5

On my desktop, I have a folder called rust. Within that folder I have another folder called hello_world.

At the command line, within the rust folder typing $ ls -la it shows the access rights to the folder hello_world as drwxr-xr-x. I am the only user and administrator on my computer - I own and have full permissions with all files and folders.


#6

Could you perhaps share the binary you’ve built?


#7

Sure thing, here it is on my GitHub.

https://github.com/0x0936/temp_rust_repo


#8

Problem solved. Moving the project directory into C:\ allowed me to run the program.

Taking another look at permissions from before, the Desktop folder doesn’t have write permissions - I don’t understand why, I can Create/Read/Update/Delete/Execute files on my desktop. This is the first time I’ve seen this issue.

Thanks again for your time retep998, and I hope this helps anyone else that may stumble upon this issue.