컴파일 (GCC)
리눅스의 가장기본적인 도구인 컴파일러에 대해
컴파일러가 컴파일을 할때 나오는 과정
처음 나오는 a.c 라는 파일을 생성하여
vi a.c
#include <stdio.h>
int main(){
printf("Hello ubunutu \n");
return 0;
}
이거 처음 알았네.. 다른 블로그에서 보기만 헀지..
위의 코드를 작성하고
root@ubuntu:~# gcc a.c //컴파일러 실행
root@ubuntu:~# ls //리스트 확인
a.c a.out // a.out 생성 확인
root@ubuntu:~# ./a.out // a.out 실행
Hello ubunutu //a.out 출력 결과
일단 GCC로 컴파일이 잘 되서 a.out까지 결과가 잘 나온다.
코드 상에서 #include 는 왜 쓰는것일까 ?
이전까지는 별로 의문이지 않았지만 한번 생각해 본다면
#include <stdio.h>를 쓰지 않고도 컴파일이 가능하다. 일단
#include <stdio.h>를 주석처리 하고 컴파일 해보자,
//#include <stdio.h>
int main(){
printf("Hello ubunutu \n");
return 0;
}
root@ubuntu:~# gcc a.c
a.c: In function ‘main’:
a.c:6:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf("Hello ubunutu\n");
^
a.c:6:2: warning: incompatible implicit declaration of built-in function ‘printf’
a.c:6:2: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
root@ubuntu:~#
워닝메세지는 printf가 암시적 선언, 뭐 이런거지만 printf 함수가 있는 헤더가 선언되지 않았다.
함수를 쓰기 전에 선언을 해야함 . C언어를 공부했다면 다 아는 것이지만
그러나 헤더 파일 없이 선언부를 넣으면 실행이 가능하다.
printf 는 int 를 반환하고 const char * 를 아규먼트를 받으며 , 가변인자인 ...를 하면
//#include <stdio.h>
int printf( const char * , ...);
int main(){
printf("Hello ubunutu \n");
return 0;
}
root@ubuntu:~# gcc a.c
root@ubuntu:~# ls
a.c a.out
root@ubuntu:~#
문제 없이 컴파일 되는것을 확인 할수 있다.
선언문을 다 쓰게 되면 너무 지저분하고 복잡하기 때문에 헤더파일을 쓰는것을 알수 있다.
임시 저장
'Linux > system programming' 카테고리의 다른 글
리눅스 서버에서 커널 파일 다운로드 (0) | 2021.03.15 |
---|---|
Vi 설정 (0) | 2021.03.14 |
FTP 서버 설정 _ SFTP접속 Filezilla사용 (0) | 2021.03.14 |
버추얼박스 리눅스서버에 putty 접속 root 권한 (0) | 2021.03.11 |
버추얼박스에서 우분투서버 끄기 (0) | 2021.03.10 |