c ++调用c函数 [英] c++ calling c functions
问题描述
i我正在尝试将2个项目合并到一个项目中。一个项目使用c />
语言,另一个项目使用c ++代码。
两者都是独立工作。但现在我需要合并两个
和我的c ++代码应该调用c代码。但是当我试图调用一个函数
在c代码中用我的c ++代码替换该函数,我得到了
未解决的外部符号错误。无论我尝试给予更多和
更多错误......所以可以合并2个项目吗?
如果是这样我怎么能这样做? br />
请回复....
- Thejaswini
< blockquote> 12月5日上午9:20,teju< tejaswini_ra ... @ yahoo.co.inwrote:
hi,
i我正在尝试将2个项目合并到一个项目中。一个项目使用c
语言,另一个项目使用c ++代码。
两者都是独立工作。但现在我需要合并两个
和我的c ++代码应该调用c代码。但是当我试图调用一个函数
in c code在我的c ++代码中交换该函数,我得到
未解决的外部符号错误。无论我尝试给予更多和
更多错误......所以可以合并2个项目吗?
如果是这样我怎么能这样做?
这是关于你想要什么的好文章<混合c和c ++代码>
http://developers.sun.com/solaris/articles/mixing.html
希望它会有所帮助。
>
请回复....
- Thejaswini
-Raxit Sheth
teju写道:
> ;
i我正在尝试将2个项目合并到一个项目中。一个项目是使用c语言的
,另一个是使用c ++代码。
两者都是独立工作。但是现在我需要合并
两者和我的c ++代码应该调用c代码。但是当我试图调用
a函数时在我的c ++代码中交换该函数的c代码中,我得到了未解决的外部符号错误
。无论我尝试它的
给出越来越多的错误......那么可以合并2
项目吗?
如果那我该怎么办呢?
请遵循以下组织。结果适用于C和
C ++。
-----------来自这里的说明------ --------
/ *一个用于链接到C ++的C头文件* /
/ *跳过一秒的正常规定要求* /
#ifdef __cplusplus
extern" C"
{
#endif
/ *这是完整的.h文件,在C * /
/ *中使用,除非上述第二次请求跳过* /
#ifdef __cplusplus
}
#endif
---------结束修好的c头-------
顺便说一句,这一切都是完全标准的ISO C.
-
Chuck F(cinefalconer at maineline dot net)
< http://cbfalconer.home.att.net>
尝试下载部分。
-
通过 http://www.teranews.com
CBFalconer< cb ******** @ yahoo.comwrote in message
news:47 ***** ********** @ yahoo.com ...
teju写道:
i我正在尝试将2个项目合并到一个项目中。一个项目是使用c语言的
,另一个是使用c ++代码。
两者都是独立工作。但是现在我需要合并
两者并且我的c ++代码应该调用c代码。但是当我试图在c代码中调用
a函数时在我的c ++代码中交换该函数,我是
得到未解决的外部符号错误。无论我尝试它的
给出越来越多的错误......那么可以合并2
项目吗?
如果那我该怎么办呢?
请遵循以下组织。结果适用于C和
C ++。
我们在这里越来越近......
-------- ---请注意--------------
/ *一个C头文件,用于链接到C ++ * /
....或用于链接到C的C ++头文件...
/ *跳过第二个请求的正常规定* /
....这里是任何正常的外部数据声明......然后是
外部函数声明:
#ifdef __cplusplus
extern" C"
{
#endif
/ *这是完整的.h文件,在C * /
中使用
不,只是外部函数声明,以通常的形式:
extern void my_callable_function(void);
....
如果你从C ++调用C函数,这就是你需要做的全部。
但是,请仔细检查外部C ++函数声明
,以获取返回值和类型的参数,这些类型不是从C编程语言允许的
基本类型派生的。
如果是这样,你就不能用C调用那个函数。你将不得不写一个
C ++包装器。函数来转换参数和/或将
值返回到允许的C类型,或以其他方式修改您的
包含文件typedef或C ++源以解决这种差异。
/ *禁止上述跳过第二次请求* /
???
#ifdef __cplusplus
}
#endif
-------- - 修复后的c头结束-------
顺便说一下,所有这些都是完全标准的ISO C.
嗯,是的,总的来说......
---
William Ernest Reid
hi,
i am trying 2 merge 2 projects into one project.One project is using c
language and the other one is using c++ code.
both are working very fine independently.But now i need to merge both
and my c++ code should call c code.but when i tried to call a function
in c code externing that function in my c++ code, i am getting
unresolved external symbol error. Whatever i try its giving more and
more errrors...so is it possible to merge 2 projects?
if so how can i do that?
please reply....
- Thejaswini
On Dec 5, 9:20 am, teju <tejaswini_ra...@yahoo.co.inwrote:hi,
i am trying 2 merge 2 projects into one project.One project is using c
language and the other one is using c++ code.
both are working very fine independently.But now i need to merge both
and my c++ code should call c code.but when i tried to call a function
in c code externing that function in my c++ code, i am getting
unresolved external symbol error. Whatever i try its giving more and
more errrors...so is it possible to merge 2 projects?
if so how can i do that?this is nice article about what you want <mixing of c and c++ code>
http://developers.sun.com/solaris/articles/mixing.html
hope it will helpful.>
please reply....
- Thejaswini-Raxit Sheth
teju wrote:>
i am trying 2 merge 2 projects into one project.One project is
using c language and the other one is using c++ code.
both are working very fine independently.But now i need to merge
both and my c++ code should call c code.but when i tried to call
a function in c code externing that function in my c++ code, i am
getting unresolved external symbol error. Whatever i try its
giving more and more errrors...so is it possible to merge 2
projects?
if so how can i do that?Follow the following organization. The result works for both C and
C++.
----------- note from here on --------------
/* a C header file for linking to C++ */
/* the normal provisions for skipping on a second request */
#ifdef __cplusplus
extern "C"
{
#endif
/* Here is the complete .h file, as used in C */
/* barring the above skip on second request */
#ifdef __cplusplus
}
#endif
--------- end of repaired c header -------
By the way, all this is perfectly standard ISO C.
--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
CBFalconer <cb********@yahoo.comwrote in message
news:47***************@yahoo.com...teju wrote:
i am trying 2 merge 2 projects into one project.One project is
using c language and the other one is using c++ code.
both are working very fine independently.But now i need to merge
both and my c++ code should call c code.but when i tried to call
a function in c code externing that function in my c++ code, i am
getting unresolved external symbol error. Whatever i try its
giving more and more errrors...so is it possible to merge 2
projects?
if so how can i do that?
Follow the following organization. The result works for both C and
C++.We''re getting closer here...
----------- note from here on --------------
/* a C header file for linking to C++ */....or C++ header file for linking to C...
/* the normal provisions for skipping on a second request */
....and here are any normal external data declarations...then for
the external function declarations:
#ifdef __cplusplus
extern "C"
{
#endif
/* Here is the complete .h file, as used in C */No, just the external function declarations, in the usual form:
extern void my_callable_function(void);
....
If you are calling a C function from C++, that is all you need to do.
However, check your external C++ function declarations carefully
for return values and arguments of types not derived from or of the
fundamental types allowed by the C programming language.
If so, you can''t call that function from C. You''ll have to write a
C++ "wrapper" function to translate the arguments and/or return
value into allowed C types, or in some other way modify your
include file typedefs or C++ source to account for this discrepancy.
/* barring the above skip on second request */???
#ifdef __cplusplus
}
#endif
--------- end of repaired c header -------
By the way, all this is perfectly standard ISO C.Well, yeah, in general...
---
William Ernest Reid
这篇关于c ++调用c函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!