我需要将file_1.c包含到main.c中.在file_1.c中,我目前有多个功能.如果我想在main.c中调用这些函数,我需要做什么?我的主程序中有#include"file_1.c".
通过制作头文件使用标准方法
#include"file_1.h"
你必须与它"file_1.c"一起编译main.c并生成一个可执行文件,因为在运行时需要函数调用.
试试这个 :
创建一个头文件 file_1.h
#ifndef _FILE_H
#define _FILE_H
void foo(int );
#endif
Run Code Online (Sandbox Code Playgroud)
给出函数和结构定义(如果有的话)或任何全局变量的所有声明
然后file_1.c将包含实际的功能定义
//file_1.c
#include "file_1.h"
#include <stdio.h>
void foo(int x)
{
printf("%d\t",x);
}
//main.c
#include "file_1.h"
int main()
{
int x=10;
foo(x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
file_1.h在两个(main.c和file_1.c)文件中包含头c文件
在 gcc
gcc -Wall main.c file_1.c -o myexe.out
| 归档时间: |
|
| 查看次数: |
1712 次 |
| 最近记录: |