cannot open output file test: Is a directory collect2: ld returned 1 exit status

26,263

Solution 1

There is a directory named "test" at the path you are trying to compile from, either rename the directory or change the output filename (-o somethingelse) . Optionally (and the best option) is to move test.c to it's own directory and compile from there.

Solution 2

At the shell prompt you issued the gcc command at, try "cd test". If it doesn't error and you get into a subdirectory called test, then the problem is exactly what the error message says. To fix that, try changing the "test" after the "-o" to some other name.

Share:
26,263

Related videos on Youtube

Bruno Pereira
Author by

Bruno Pereira

Father of happy young brat. Loves Belgium beers, good cognacs and perfect espressos. Loves cooking for friends, a good conversation or a book. Is interested in everything tech, specially open source and has a extensive computer background. Can be contacted by mail, facebook, linkedin and when I am not lazy I can trow a thought or two in twitter @bpereira81.

Updated on September 17, 2022

Comments

  • Bruno Pereira
    Bruno Pereira over 1 year

    I want to compile the program using these command:gcc -o test test.c,then it displays these:

    yangbin@yangbin-desktop:~/桌面$ gcc -o test test.c
    /usr/bin/ld: cannot open output file test: Is a directory
    collect2: ld returned 1 exit status
    

    I cannot understand why,please give me a hand to solve it! I am a freshman.

    /*****test.c*********/
    #include
    int main(void)
    {
            int input=0;
            printf("enter an integer:");
            scanf("%d",&input);
            printf("Twice the number you supplied is %d\n",2*input);
            return 0;
    }
    
  • mtaanquist
    mtaanquist over 13 years
    I have try following what you said,but ...you know ,the problem still alive!