c++链接错误,高手请帮忙

heaven33 2009-05-24 08:28:52
如下3个文件:
//h1.h
#ifndef H1_H
#define H1_H
extern int aa(int x, int y);
#endif
//h1.c
#include "h1.h"
int aa(int x , int y)
{
return x+y;
}
//cpp1.cpp
#include <iostream>

extern "C"
{
#include "h1.h"
}

using namespace std;




int main()
{
cout << aa(1,2);
}


为什么链接的时候报错呢?
g:\program files\microsoft visual studio\myprojects\projecttest\cpp1.cpp(55) : error C2064: term does not evaluate to a function
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
coreyao1988 2009-05-25
  • 打赏
  • 举报
回复
lz是用什么编译器的?
我vs2008通过的
我觉得因为h1.c是C文件,函数的连接规范是C的
而cpp1.cpp是cpp文件,连接规范不一样,所以要加extern "C"
goodname 2009-05-24
  • 打赏
  • 举报
回复
如果非要写上,可以这样改。

//h1.h
#ifndef H1_H
#define H1_H
#ifdef __cplusplus
extern "C" {
#endif

extern int aa(int x, int y);

#ifdef __cplusplus
}
#endif

#endif
lpf000 2009-05-24
  • 打赏
  • 举报
回复
//h1.c
#include "h1.h"
extern "C" int aa(int x , int y)
{
return x+y;
}
//
lzh9955 2009-05-24
  • 打赏
  • 举报
回复
extern "C"
{
#include "h1.h"
}

extern "C"
{
}
干什么? 无法决议!
yangch_nhcmo 2009-05-24
  • 打赏
  • 举报
回复

//extern "C"
//{
#include "h1.h"
//}

goodname 2009-05-24
  • 打赏
  • 举报
回复
extern "C"
{
#include "h1.h"
}


改为
#include "h1.h"

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧