加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

QT中使用C代码-extern“C”:expectedidentifieror‘(’beforestringconstant

(2018-08-27 10:17:38)
分类: QT
extern "C"的惯用法

第一种方法:

在C++ 文件中

extern "C"

{

    #include"cExample.h"

}

第二种方法:在头文件中

             

#ifdef __cplusplus                     

extern "C" {

#endif

int add(int a, int b);

#ifdef __cplusplus

}

#endif

总结:.cpp为c++文件,makefile默认使用g++,.c为c文件,makefile默认使用gcc,如果使用gcc编译,不使用__cplusplus宏,直接用extern “C”则会报错。报错为expected identifier or ‘(’ before string constant。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有