Skip to content

It is not possible to compile a file named "rust.rs" on Linux #35887

Closed
@c410-f3r

Description

@c410-f3r
Contributor

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

Activity

durka

durka commented on Aug 22, 2016

@durka
Contributor

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

c410-f3r commented on Aug 22, 2016

@c410-f3r
ContributorAuthor

@durka Guess it is not a bug after all

retep998

retep998 commented on Aug 22, 2016

@retep998
Member

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

dashed

dashed commented on Aug 22, 2016

@dashed

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

0xmohit commented on Aug 22, 2016

@0xmohit
Contributor

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

estebank commented on Aug 22, 2016

@estebank
Contributor

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

alexcrichton

alexcrichton commented on Sep 13, 2016

@alexcrichton
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

varkor commented on Jan 30, 2018

@varkor
Member

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

added a commit that references this issue on Feb 6, 2018

Auto merge of #47203 - varkor:output-filename-conflicts-with-director…

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @durka@alexcrichton@dashed@retep998@estebank

        Issue actions

          It is not possible to compile a file named "rust.rs" on Linux · Issue #35887 · rust-lang/rust