我想在一个文件中调用另外一个文件中的函数,如下面是主函数:
#include "stdio.h"
#include "temp.h"
void main()
{
int k,j=10;
k=aa(j);
}
下面为temp.h:
#include "stdio.h"
extern int aa(int i);
下面为temp.c:
#include "temp.h"
int aa(int i){
i=10;
printf("aaaaaa");
return i;
}
为什么编译时总报错:
error LNK2001: unresolved external symbol "int __cdecl aa(int)" (?aa@@YAHH@Z)
#include "stdio.h"
#include "temp.h"
void main()
{
int k,j=10;
k=aa(j);
}
下面为temp.h:
#include "stdio.h"
extern int aa(int i);
下面为temp.c:
#include "temp.h"
int aa(int i){
i=10;
printf("aaaaaa");
return i;
}
为什么编译时总报错:
error LNK2001: unresolved external symbol "int __cdecl aa(int)" (?aa@@YAHH@Z)
你可以在main()函数中#incluee "temp.cpp"
extern int aa(int i)
告诉编译器,这个函数是别的文件中的函数
在main()前加extern int aa(int i)
报同样的错。
应该 在main()前加 yjs_soft所说的
extern "C" extern int aa(int i);
你可以在temp.h中这样声明
#ifdef __cplusplus
extern "C" {
#endifextern int aa(int i);#ifdef __cplusplus
}
#endif
请问一下在Turbo C下怎么写呢?
请问一下在Turbo C下怎么写呢?
{
#include "temp.h"
}
不行,加了extern "C" 编译报定义不正常结束,编译器不认得 “C"
我的文件是以.c命名。
(1)单独把 temp.c编译成 temp.obj
(2)把主文件编译成 XX.obj
(3)手工连接 成 XX.exe或者
你可以设置TC环境里的 主文件
为什么在Turbo C++下加extern "C" 编译报定义不正常结束,编译器不认得 “C"
#include "temp.h"
void main()
的第三行加入
#include "temp.c"
程序也不会出错的!
但一般写程序时不会把.c文件include 进来的。