gcc编译器入门

004_wz_bbk_用GCC编译第一个C程序及多文件编程

2020-10-08  本文已影响0人  王泽0106

Compiling a Simple C Program

The classic example program for the C language is:

#include <stdio.h>

int main(void)
{
printf("hello world!\n");
 return 0;
}

To compile the file with gcc,use the following command:

gcc -Wall hello.c -o hello

Example1

  1. 建立文件vim hello.c,键入C源码
  2. 编译文件gcc -Wall hello.c -o hello(指定编译文件名为hello,默认为a.out)
  3. 执行文件./hello
exp1

Compiling Multiple Source Files

Example2

  1. 建立文件vim hello.h
void hello(const char* string);
  1. 建立文件vim hello.c
#include <stdio.h>
#include "hello.h"

void hello(const char* string)
{
printf(string);
}
  1. 建立文件vim main.c
#include <stdio.h>
#include "hello.h"

int main(void)
{
hello("hello world!");
return 0;
}
  1. 编译文件gcc -Wall hello.c main.c -o newhello
  2. 执行文件./newhello
exp2

2020.10.8

上一篇 下一篇

猜你喜欢

热点阅读