问题:C语言头文件怎么写,C语言头文件有一个与之对应的.c文件或者.cpp文件,.h文件和.c文件对应同名,然而为什么(#include)调用.h文件会出错,而调用.c文件就能够运行,与头文件同名的.c文件实现了.h文件中声名的函数的功能,语法上没有问题
操作系统:win10
编译环境:Visual Studio 2012
编译器出错原因:在main.c程序中#include "test.h",而#include "test.c"就无出错信息
编译器出错信息:错误 2 error LNK1120: 1 个无法解析的外部命令
编译器出错信息:错误 1 error LNK2019: 无法解析的外部符号 "void __cdecl print(void)" (?print@@YAXXZ),该符号在函数 _main 中被引用
头文件:test.h
//test.h
#ifndef _TEST_H_
#define _TEST_H_
#include <stdio.h>
void print();
#endif
头文件对应的c文件:test.c
//test.c
#include "test.h"
void print()
{
printf("jjjjjjjj\n");
}
主程序:main.c
//main.c
#include "test.h"
#include <stdlib.h>
int main()
{
print();
system("pause");
return 0;
}