1

I am new to C++ and I know compilers compile C++ source file into .o file and linker makes the executable file using those .o files (I am not sure about this). And I know g++ -o program.exe program.cpp compiles C++. So, my questions are:-

  1. Why that command directly make an executable file instead of creating object file?

  2. This command would just compile C++ source file. So, when did I used the linker so that there will be an executable file?

I know it's a dumb question but I searched in google and I found nothing about it.

  • Does [this](https://stackoverflow.com/questions/5759353/is-g-both-a-c-compiler-and-a-linker) answer your question at all? – Nathan Pierson May 02 '21 at 15:04
  • That command complies the source file to an object file and then links the object file to the standard library. If you wrote `g++ -c program.cpp` the compiler would not call the linker; '-c` means compile only. – Pete Becker May 02 '21 at 16:53
  • Thanks @PeteBecker! But can ```g++ -c program.cpp``` command also compile two C++ file? If yes, then how? –  May 02 '21 at 21:09
  • @rajin100000 -- try it. – Pete Becker May 02 '21 at 22:10

0 Answers0