There are 2 files: Element.cpp and Element.h .

In main.cpp I connect Element.h . But how does the compiler know when and where to attach the Element.cpp file in which the implementation is stored? After all, I do not prescribe it anywhere.

    1 answer 1

    The compiler does not know. When compiling, it specifies which .срр files to compile, for example

     g++ file1.cpp file2.cpp 

    and in all .cpp files you need to specify the necessary header files. If you are working in the IDE, then the compiler will automatically transfer the source code files that are included in the project.

    • one
      oh damn, this is a twist) thanks. - Maxmaxmaximus
    • and if I registered the header and forgot to connect the implementation (well, let's say I forgot to connect in the compiler settings), then the header is simply not compiled, saying "header, but there is no implementation"? - Maxmaxmaximus
    • 3
      yes, you get an unresolved external symbol build error unresolved external symbol - Yuriy Orlov
    • one
      The entry point only determines where the executable file will run from. If you compile the library ( .lib , .so , etc.), then the compilation and build will take place in exactly the same way, only the main functions should not be because the library will be included in the executable file, and if it is present, 2 entry points will be detected that is unacceptable. - Yuriy Orlov
    • one
      @ user2966664: Not at that time, when C ++ was invented, it was decided to charge all the boring work of connecting all the necessary files to the programmer himself. More modern languages ​​are more humane in this respect. - VladD