0

According to How does the compilation/linking process work?

During compilation, the compiler takes the pre-processor's output and produces an object file from it.

Additionally,

Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file.

So for example:

If I have 2 files test1.cpp and test2.cpp. I can do modular compilation with g++ -c test1.cpp test2.cpp which generates 2 object files test1.o and test.o.

But what about during single step compilation? Where I have 1 file test1.cpp. With the command g++ test1.cpp, no object file appears to be generated in the directory. So what happens during single step compilation?

csguy
  • 1,354
  • 2
  • 17
  • 37
  • 1
    The C++ Standard has nothing to say about how compilation and/or linking must work. This is down to the compiler and linker implementation. –  Aug 05 '19 at 20:33
  • "With the command g++ test.cpp, no object file appears to be generated" - Then you need to look harder. Unless the compilation failed, that should most definitely produce an object file. – Jesper Juhl Aug 05 '19 at 20:34
  • @NeilButterworth moot point. OP didn't ask about C++ standard quote on that. – SergeyA Aug 05 '19 at 20:34
  • @JesperJuhl with given command, it won't. – SergeyA Aug 05 '19 at 20:35
  • @Sergey It is tagged as C++ and contains `(C++)` in the headline. –  Aug 05 '19 at 20:35
  • @NeilButterworth so what? There are numerous C++ questions which are of application domain nature. Are you going to say that C++ Standard says nothing abouy, say, SFML (very popular topic in the tag)? I also disagree with your duplicate, OP is asking specific, g++ question. I would like to reopen the question. – SergeyA Aug 05 '19 at 20:36
  • Yes, I am and often do. –  Aug 05 '19 at 20:37
  • 1
    " I would like to reopen the question" - is anyone stopping you? –  Aug 05 '19 at 20:37
  • @NeilButterworth I think this would be very narrow reading. Questions for standards are tagged with Language Lawyer, and I see no issue with application domain questions in C++ tag. Well, the last thing I want is to get in tug of war here. You certainly had you reasons to close it, and I would like to see if you would reconsider and agree that the question might deserve an answer on it's own. – SergeyA Aug 05 '19 at 20:39

1 Answers1

2

This has to do with g++ command line. If you just run it with

g++ file.cpp

It will compile the code to intermediate object file, and than invoke linker and create a.out executable file, removing the intermediate object file after this.

SergeyA
  • 61,605
  • 5
  • 78
  • 137