4
votes

I can't figure out why i can't compile my program with

    g++ -std=c++0x main.cpp Sale.h iProduct.h -o w7

every time i try and compile with this command i get a clang error

    clang: error: cannot specify -o when generating multiple output files

the program complies fine as a.out and i know i could just rename the a.out file and be on my way but i would like to know why I'm getting this error and how i should fix it. Thanks

1
Don't specify .h files in the command line. Just g++ -Wall -std=c++0x main.cpp -o w7 is all you need.Paul R
Thank you @PaulR that worked, may I ask why do the .h files affect it?Gabriel Appugliese
Header files (.h suffix) are typically intended to be #included by .cpp files, so they don't need to be compiled separately.Paul R

1 Answers

2
votes

why I'm getting this error and how i should fix it may I ask why do the .h files affect it?

Because of recent versions of gcc can compile heaader files, Example:

g++ test.h -o out
file out
out: GCC precompiled header (version 014) for C++

It(gcc) produce precompiled files (https://en.wikipedia.org/wiki/Precompiled_header) in this case.

So when you compile .cpp file and header at the same time, it can not decide what produce as output precompiled headers, or elf executable.