많은 개발자들이 간과하는 부분이다.
하지만 workflow를 지켜야 효율적인 개발이 가능하다.
Workflow는 다음과 같다.
Step 1. Define the problem to solve.
Step 2. Design a solution.
Step 3. Write a program that implements the solution.
Step 4. Compile the program.
Step 5. Link object files and libraries.
Step 6. Test program.
Step 7. Debug. Go back to Step 4.
Step 1. Define the problem to solve.
예시
"나는 사용자에게 여러 숫자를 입력 받고 숫자들의 합을 출력하는 프로그램을 작성하고 싶어."
Step 2. Design a solution.
좋은 solution의 특징
1. 직관적이다.
2. 문서화되어 있다.(특히 전제와 한계점에 대해서)
3. 모듈식으로 설게되어 있다.(모듈이 재사용 가능하도록)
4. Robust하다. 예상치 못한 에러가 발생해도 recover하거나 에러 메세지를 띄울 수 있다.
Step 3. Write a program that implements the solution.
프로그램을 작성하기 위해서는 2가지가 필요하다.
1. Programming Language에 대한 지식
2. Text editor
#include <iostream>
int main()
{
std::cout << "Here is some text.";
return 0;
}
Step 4. Compile the program.
Compiler는 우리의 소스코드를 훑으면서 문법 체크와 머신 코드로의 변환을 수행한다.
머신 코드는 object file에 저장되는데 object file은 Step 5, 6, 7에서 유용한 metadata라는 것도 포함한다.
Object file은 .o 확장자를 가진다.
Step 5. Link object files and libraries.
Compile이 작업을 마친 후 Linker는 모든 object 파일들을 합치고 executable file을 만든다.
Linker의 세부 작업 process는 아래와 같다.
1. Linker는 compiler가 뱉어난 모든 object 파일을 훑으면서 유효성 검사를 한다.
2. Linker는 모든 dependency가 만족하는 지 검사한다.
3. Linker는 library file을 linking한다. Library file은 다른 프로그램에서 갖다 쓰기 쉽게 만들어진 precompile된 코드다. 대표적으로 C++ Standard Library가 있다. 자주 쓰는 <iostream>도 C++ Standard Library다.
Building
Building : 소스 코드를 compiling과 linking을 포함하여 executable로 바꾸는 작업
Bulid : Building을 통해 산출된 executables
* make처럼 build를 자동화할 수 있는 tool들이 종종 사용된다.
Step 6 & 7. Testing and Debugging the program.
Reference
[1] https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/
'C++' 카테고리의 다른 글
build, clean, rebuild, compile, run/start (0) | 2024.02.19 |
---|---|
What is Project and Workspace(or Solution)? (0) | 2024.02.19 |
C++ IDE 설치하기 (1) | 2024.02.19 |
C, C++의 철학과 역사 (0) | 2024.02.18 |
Compiler vs Interpreter (0) | 2024.02.18 |