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。
第一种方法:
在C++ 文件中
extern "C"
{
}
第二种方法:在头文件中
#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。

加载中…