Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't compile a file named "rust.rs" on Linux #35887

Closed
c410-f3r opened this issue Aug 22, 2016 · 8 comments
Closed

Can't compile a file named "rust.rs" on Linux #35887

c410-f3r opened this issue Aug 22, 2016 · 8 comments

Comments

@c410-f3r
Copy link
Contributor

c410-f3r commented Aug 22, 2016

It is not possible to compile a file whose name is equal to a directory already created in the same folder:

$ rustc rust.rs
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "rust.0.o" "-o" "rust" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-39b92f95.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: /usr/bin/ld: cannot open output file rust: Is a directory
collect2: error: ld returned 1 exit status

error: aborting due to previous error
@durka
Copy link
Contributor

durka commented Aug 22, 2016

Not really a rust bug.

$ mkdir foo
$ echo "int main() { return 0; }" >foo.cpp
$ g++ foo.cpp -o foo
ld: can't open output file for writing: foo, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@c410-f3r
Copy link
Contributor Author

@durka Guess it is not a bug after all

@retep998
Copy link
Member

You cannot have both a file and a directory with the exact same name in the same directory.

@dashed
Copy link

dashed commented Aug 22, 2016

There could be a nicer error message to indicate to the user that there is a directory with the same name as the program.

@0xmohit
Copy link
Contributor

0xmohit commented Aug 22, 2016

FWIW, gcc behaves similarly.

$ ls 
$ echo "int main() { return 0; }" > a.c
$ mkdir a.out
$ ls
a.c  a.out
$ gcc a.c
/usr/bin/ld: cannot open output file a.out: Is a directory
collect2: error: ld returned 1 exit status
$ 

@estebank
Copy link
Contributor

I could expand #34005 when I get back to it to clean it up to pick this case up as well.

@alexcrichton
Copy link
Member

Ah yes I think this is "not a bug" where we can't create executables with a directory of the same name, so closing.

varkor added a commit to varkor/rust that referenced this issue Jan 29, 2018
When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in rust-lang#35887.
@varkor
Copy link
Member

varkor commented Jan 30, 2018

Just to note: this is a duplicate of #13098.

bors added a commit that referenced this issue Feb 6, 2018
…y, r=estebank

Warn when rustc output conflicts with existing directories

When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in #35887. Fixes #13098.
bors added a commit that referenced this issue Feb 6, 2018
…y, r=estebank

Warn when rustc output conflicts with existing directories

When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in #35887. Fixes #13098.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants