GCC编译多个C文件

原文地址为: GCC编译多个C文件

下午做了一个小的程序,定义了三个文件:getop.h,getop.c,calcDemo.c

显然getop.h是针对getop.c的,而在calcDemo.c中要调用到getop.c中的东西。

首先给出每个文件的结构图,为了更简单的说明,函数都空实现。

getop.h:

#ifndef _H_GETOP
#define _H_GETOP
 int getch(void);
 void ungetch(int c);
 int getop(char s[]);
#endif

getop.c

#include <stdio.h>
#include <ctype.h>
#define NUMBER '0'
int getch(void);
void ungetch(int);


int getop(char s[])
{
 return 0;

}

#define BUFSIZE 100
char buf[BUFSIZE];
int bufp =0;

int getch(void)
{
  return 0;
}

void ungetch(int c)
{

}

calcDemo.c

#include <stdio.h>
#include <stdlib.h>
#include "getop.h" //只需这样引用即可

最后,即是利用gcc来编译这几个文件:

gcc getop.c calcDemo.c -o output.out

编译后的目标文件即为:output.out

然后执行:./output.out即可


 


转载请注明本文地址: GCC编译多个C文件

猜你喜欢

转载自blog.csdn.net/dearbaba_8520/article/details/81662311