Mixing C with C++ in CW7.1

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Mixing C with C++ in CW7.1

1,240 次查看
SVC2
Contributor II


Hi,

I have a whole project written in C, tested and running.

 

I would like to add any new file in CPP.

 

Is that possible without having to alter all existing files?

 

Is it possible to use


#ifdef __cplusplus
#pragma cplusplus on
#endif // __cplusplus

 

 

in the newly added CPP files without changing the project compiler settings (i.e., Force C++)?

 

Thanks,

SVC

标签 (1)
标记 (1)
0 项奖励
回复
1 回复

666 次查看
eGuy
Contributor IV

I don't know if there are other easy way or not.

 

What I know is: if you want to use functions defined in C from C++, in the C header file, you need to add some like these:

 

---------------------------------------------

 

#ifdef __cplusplus
    extern "C" {
#endif

extern float YOUR_C_FUNCTIONS( );

 

#ifdef __cplusplus
    }
#endif
 ------------------------------------------------

 

In addition, you need to link to the corresponding C++ libraries: like Cpp_4i_CF_RegABI_Runtime.a and 

C++_4i_CF_RegABI_MSL.a

 

 

In this way, you don't need to enable that "Force C++" selection

 

 

Regards,

 

Jeff

 

0 项奖励
回复