0.5 Introduction to the compiler, linker, and libraries

주홍영·2022년 3월 10일
0

Learncpp.com

목록 보기
5/199

https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/

앞서 말했던 위의 다이어그램에서 이어나간다

Step 4: Compiling your source code

c++ 프로그램을 컴파일하기위해 c++ 컴파일러를 사용한다
c++ 컴파일러는 sequentially goes through (순차적으로 진행) 각 cpp파일을, 우리의 프로그램에 다음의 두가지 중요한 task를 수행한다

First, 컴파일러는 코드가 rule을 따르고 있는지 검사한다. 만약 그렇지 않을 경우
에러를 발생시킨다 컴파일 프로세스는 에러가 fix 될 때까지 be aborted (중단된다)

Second, 컴파일러는 c++ 소스 코드를 machine language 파일로 바꾼다
이를 object file 이라고 칭한다.
C++ source code (cpp file) -> machine language (obj file)
Object file은 보통 name.o, name.obj 의 타입을 가진다 ( like cpp )

따라서 너가 3개의 cpp 파일을 가지고 있다면 컴파일러는 세개의 object 파일을 생성한다.

Step 5: Linking object files and libraries

컴파일러가 하나 또는 복수의 obj 파일을 생성하고 나면 linker라는 또 다른 프로그램이
kicks in (나타나다).
The job of the linker is three fold (링커의 역할은 세가지 입니다)

First, 컴파일러로부터 발생한 모든 obj 파일을 취합하여 하나의 executable 프로그램으로 만든다

Second, in addition to being able to link object files, the linker also is capable of linking library files. (링커는 개체 파일을 연결할 수 있을 뿐만 아니라 library file도 연결할 수 있습니다.)
라이브러리 파일은 다른 프로그램에서 재사용하기 위해 "패키징"된 미리 컴파일된 코드 모음입니다.

c++의 core language는 실제로 꽤나 작고 concise (간결한)
하지만 확장 라이브러리인 STL 이 존재한다 (이는 부가적인 functionality를 제공함)
대표적으로 iostream (모니터에 텍스트를 프린팅하고 키보드 입력받는 기능)

Third, Third, the linker makes sure all cross-file dependencies are resolved properly. (링커는 모든 파일간 종속성이 올바르게 해결되었는지 확인한다)

이러한 종속성이 해결되지 않으면 linker error가 발생한다. linking process가 abort(중단)된다

링커가 obj 파일과 library 파일을 linking 하고나면 executable file (.exe)가 만들어진다

For advanced readers

복잡한 프로젝트에서 때로는 makefile을 사용한다. 이는 어떻게 프로그램이 build되는지 묘사한 파일이다. 하지만 c++의 core language도 아닐뿐더러 진행하는데 필요하지도 않다
따라서 다루지 않는다

Steps 6 & 7: Testing and Debugging

이제 실행할 수 있고 만약 의도한대로 작동하지 않는다면 디버깅과정을 통해 수정한다

Integrated development environments (IDEs)

step 3,4,5, 7은 모두 소프트웨어가 필요한 과정이다 (순서대로 editor, compiler, linker, debugger)
모두 각자 개별적이 소프트웨어지마나 IDE는 이를 통합해 개발환경을 제공해준다
Integrated

단어장

sequentially goes through (순차적으로 진행)
be aborted (중단된다)
The job of the linker is three fold (링커의 역할은 세가지 입니다)
in addition to being able to link object files, the linker also is capable of linking library files. (링커는 개체 파일을 연결할 수 있을 뿐만 아니라 library file도 연결할 수 있습니다.)
concise (간결한)
Third, the linker makes sure all cross-file dependencies are resolved properly. (링커는 모든 파일간 종속성이 올바르게 해결되었는지 확인한다)
resolve 해결하다

profile
청룡동거주민

0개의 댓글