반응형
    
    
    
  C언어.
1. 함수 등록.
| 1 2 3 4 5 6 7 8 9 10 11 12 | // test.c #include <stdio.h> int add(int a, int b); int main(){     printf("%d\n", add(1, 2));         return 0; } | 
| 1 2 3 4 5 6 | // add.c int add(int a, int b){     return a + b; } | cs | 
명령어.
$ gcc test.c add.c
(오브젝트 파일 과정과 실행파일 지정 생략 가능)
2. 헤더 파일선언
| 1 2 3 4 5 6 7 8 9 10 11 | // add.h #ifndef _ADD_H_ #define _ADD_H_ #include <stdio.h> int add(int a, int b); #endif | 
| 1 2 3 4 5 6 | // add.c int add(int a, int b){     return a + b; } | cs | 
| 1 2 3 4 5 6 7 8 9 10 11 | // test.c #include <stdio.h> #include "add.h" int main(){     printf("%d\n", add(1, 2));         return 0; } | cs | 
명령어.
$ gcc test.c add.c
(오브젝트 파일 과정과 실행파일 지정 생략 가능)
C++.
| 1 2 3 4 5 6 7 8 9 10 11 | // test.cpp #include <iostream> int add(int a, int b); int main(){     std::cout << add(1, 2) << std::endl;     return 0; } | cs | 
| 1 2 3 4 5 | // add.cpp int add(int a, int b){     return a + b; } | cs | 
명령어.
$ g++ test.cpp add.cpp
(오브젝트 파일 과정과 실행파일 지정 생략 가능)
헤더파일 선언
| 1 2 3 4 5 6 7 8 9 10 | // add.hpp #ifndef _ADD_H_ #define _ADD_H_ #include <iostream> int add(int a, int b); #endif | cs | 
| 1 2 3 4 5 | // add.cpp int add(int a, int b){     return a + b; } | cs | 
| 1 2 3 4 5 6 7 8 9 10 | // test.cpp #include <iostream> #include "add.hpp" int main(){     std::cout << add(1, 2) << std::endl;     return 0; } | cs | 
명령어.
$ g++ test.cpp add.cpp
(오브젝트 파일 과정과 실행파일 지정 생략 가능)
반응형
    
    
    
  '프로그래밍 > 리눅스' 카테고리의 다른 글
| 리눅스 파이프(pipe) 에 대한 설명 ( '|' ) (4) | 2021.03.31 | 
|---|---|
| c++] make, makefile의 사용방법(기본적인 설명) (1) | 2020.05.18 | 
| gcc / g++ 사용법과 설명 (4) | 2020.05.17 | 
| 리눅스(Ubuntu18.04 ver) .bashrc, .profile, .bash_profile, .vimrc 가 없을 경우!! (0) | 2019.08.29 | 
| Ubuntu 18.04 버전 인터넷 자꾸 끊길 때 자동 Reset해주는 프로그램. (2) | 2019.08.25 | 
 
														
													
댓글