Thread: [Error] gcc.exe: cannot specify -o with -c or -S and multiple compilations

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    4

    [Error] gcc.exe: cannot specify -o with -c or -S and multiple compilations

    Its in the title. This is the error I am getting when trying to run my program within C-Free. Here is the source code. Also, this is for my Intro to C programming class so I am a bit of a noob when it comes to programming lingo. however I am very experienced with computers so I am not a computer noob, just a programming noob

    insert
    Code:
    #include <stdio.h>
    int main (void)
    {
        //* Declare Variables *//
        
        int number_of_grades, x, grade;
        float grade_average, total_grade;
    
    
        x = 1;
        total_grade = 0
        
                    //* Greeting user and asking for number of grades to process *//
                    
        printf ("The program calculates the average of as many grades you wish to enter.\n\n");
        printf ("First, please enter the number of grades to process: ");
        scanf  ("%i", &number_of_grades);
        printf ("\nNow enter the %i grades to be averaged.\n\n", number_of_grades);
        
            while ( x <= number_of_grades )
    {            printf ( "Enter grade#%i: ", x );
                scanf ( "%i", &grade );
            if ( grade >= 0  &&  grade <= 100 )
    {             total_grade = total_grade + grade;
                 ++x;
    }
             else 
                printf ( "*** Invalid entry. Grade must be 0 to 100. ***\n" );
    }
        grade_average = total_grade / number_of_grades;
        printf ( "The average of the %i grades entered is %.0f\n\n", number_of_grades, grade_average );
         
         if             ( grade_average >= 90  &&  grade_average <= 100 )
             printf ( "You have a letter grade of A\n" );
         else if     ( grade_average >= 80  &&  grade_average <= 89  )
             printf ( "You have a letter grade of B\n" );
        else if        ( grade_average >= 70  &&  grade_average <= 79  )
            printf ( "You have a letter grade of C\n" );
        else if     ( grade_average >= 60  &&  grade_average <= 69  )
            printf ( "You have a letter grade of D\n" );
        else 
            printf ( "You have a letter grade of F\n" );
    
    
        return 0;
        
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,432
    You need to look at how your IDE project is set up.

    Example command lines.
    Code:
    $ gcc -o -c -S foo.c
    foo.c: In function ‘main’:
    foo.c:45:3: warning: format not a string literal and no format arguments [-Wformat-security]
    $ gcc -o -c -S foo.c bar.c
    gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files
    compilation terminated.
    Somehow, your IDE has chosen to pass multiple source files to the compiler.

    The typical usage is to pass a single source file to the compiler, with whatever flags, and produce one (or more) .o files.

    All the .o files (along with libraries) are then combined into a single executable by a program called the linker.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    Here is the command line I found in my program

    Code:
    "$(FileName)" -c -o "$(Path)$(Name).o" $(CompilerOptions) -I$(IncPaths) -B$(ExePaths)

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,432
    > -I$(IncPaths) -B$(ExePaths)
    Do either of these expand to pathnames with spaces in them?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    Hmm.. Not sure exactly what you mean by expand.

    https://gyazo.com/60843e0aebf0eedd380af33fd0dd08c8

    That is what I am looking at. Just as some background information that may help, it was working before. I have had this program run my programs before and it is just now doing this. But when I go back to run some of my old programs I have written, I now get the error when trying to run them as well even though they worked before and I haven't edited them.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,432
    > Not sure exactly what you mean by expand.
    All those $(var) symbols are placeholders for strings defined by your IDE (or makefile). They get replaced by text substitution to generate a real command line to pass to the compiler.

    I mean spaces, as in perhaps this which appears in your build configuration line
    "MinGW (Old"


    This is probably OK
    C:\compilers\mingw\bin

    This could be problematic unless your IDE is smart enough to quote strings properly in ALL cases.
    C:\Program Files\MinGW (Old)\bin

    If it misses something, then a space in a filename becomes just another file to compile (or complain about).

    This is really a support question for here IMO -> C-Free Home - A Professional C/C++ IDE. Slightly worried that it hasn't been updated in 6 years (apparently).
    Or is it some other C-Free perhaps.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    Why is it that I can't just uninstall it and reinstall and fix it? Why would it download broken, when before it worked? Ugh...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting multiple Definitions Error ( C++)
    By Darkinyuasha1 in forum Game Programming
    Replies: 4
    Last Post: 06-27-2012, 04:32 PM
  2. Multiple Definition Error
    By ineedmunchies in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2011, 08:54 AM
  3. Multiple Definition Error
    By timmeh in forum C++ Programming
    Replies: 9
    Last Post: 02-15-2009, 12:25 PM
  4. QT error multiple declarations?
    By curlious in forum Linux Programming
    Replies: 2
    Last Post: 09-20-2005, 09:21 AM
  5. Multiple definition error
    By gustavosserra in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2003, 08:33 PM