从C访问C ++ [英] Accessing C++ from C

查看:55
本文介绍了从C访问C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在9月份的C / C ++用户期刊中,对话中提到了一种技术

。它建议如何通过将C ++包装在C中来提供从C到C ++类的通用访问。我的问题是

,我无法想象这是如何完成的。我的gcc链接器保持

抱怨它无法找到STL库成员的目标代码。

有没有其他人试图这样做并让它工作?如果是的话,你能告诉我b $ b让我知道怎么做?


谢谢,

Evan Carew

in the September issue of C/C++ Users Journal, there was a technique
mentioned in "Conversations" which suggested how to provide generic
access to C++ classes from C by wrapping your C++ in C. My problem is
that I can''t figure otu how this is done. My gcc linker keeps
complaining that it can''t find object code for the STL library members.
Has anyone else tried to do this and gotten it to work? if so, could you
let me know how?

Thanks,
Evan Carew

推荐答案

Evan Carew写道:
Evan Carew wrote:
在9月份的C / C ++用户期刊中,有一种技术成员的目标代码。
in the September issue of C/C++ Users Journal, there was a technique
mentioned in "Conversations" which suggested how to provide generic
access to C++ classes from C by wrapping your C++ in C. My problem is
that I can''t figure otu how this is done. My gcc linker keeps
complaining that it can''t find object code for the STL library
members.




这实际上是偏离主题的在这里,应该在gnu.gcc.help或

gnu.g ++。help中询问,但无论如何,如果您的

程序包含c ++,则需要使用g ++进行链接代码。



This is actually off-topic here, and should be asked in gnu.gcc.help or
gnu.g++.help, but anyway, you need to use g++ for linking if your
program contains c++ code.


2004年1月7日星期三18:36:00 -0500,Evan Carew写道:
On Wed, 07 Jan 2004 18:36:00 -0500, Evan Carew wrote:
在9月份的C / C ++ Users Journal中,有一种技术在对话中提到。它建议如何通过将C ++包装在C中来提供对C语言C ++类的通用访问。我的问题是,我无法想象如何完成这项工作。我的gcc链接器一直抱怨它无法找到STL库成员的目标代码。
有没有其他人试图这样做并让它工作?如果是的话,你能告诉我怎么做?
in the September issue of C/C++ Users Journal, there was a technique
mentioned in "Conversations" which suggested how to provide generic
access to C++ classes from C by wrapping your C++ in C. My problem is
that I can''t figure otu how this is done. My gcc linker keeps
complaining that it can''t find object code for the STL library members.
Has anyone else tried to do this and gotten it to work? if so, could you
let me know how?




充其量的诡计。链接问题可以很容易地解决,包括正确的
库路径(或者使用g ++,它会编译C代码很好,它不同于gcc

在什么包含它添加的库和路径,而不是它的源代码。


另一个问题是C ++ RTL。这可能应该初始化,

是系统相关的,可能需要也可能不需要。最简单的解决方案

就是将C main重命名为C_main,用C ++编写你的主要内容

只调用这个C_main。


HTH,

M4



Tricky at best. The linking issue can be easily solved, include the right
library path (or use g++, it''ll compile C code fine, it differs from gcc
in what include and library paths it adds, not how it looks at source code).

Another issue is the C++ RTL. That probably should be initialised, which
is system dependent and may or may not be necessary. The easiest solution
to this is to rename the C main to C_main, write your main in C++ that
only calls this C_main.

HTH,
M4


Martijn Lievaart写道:
Martijn Lievaart wrote:
On 2004年1月7日星期三18:36:00 -0500,Evan Carew写道:
On Wed, 07 Jan 2004 18:36:00 -0500, Evan Carew wrote:
在9月份的C / C ++用户期刊中,提到了一种技术
"对话"它建议如何通过将C ++包装在C中来提供对C语言C ++类的通用访问。我的问题是,我无法想象如何完成这项工作。我的gcc链接器一直抱怨它无法找到STL库
成员的目标代码。有没有其他人试图这样做并让它工作?如果
那么,你能让我知道怎么样吗?
充其量只是狡猾。链接问题可以很容易地解决,包括正确的库路径(或者使用g ++,它会很好地编译C代码,它与gcc在它添加的包含和库路径中有所不同,而不是如何它在源代码中看起来很好。
in the September issue of C/C++ Users Journal, there was a technique
mentioned in "Conversations" which suggested how to provide generic
access to C++ classes from C by wrapping your C++ in C. My problem is
that I can''t figure otu how this is done. My gcc linker keeps
complaining that it can''t find object code for the STL library
members. Has anyone else tried to do this and gotten it to work? if
so, could you let me know how?
Tricky at best. The linking issue can be easily solved, include the
right library path (or use g++, it''ll compile C code fine, it differs
from gcc in what include and library paths it adds, not how it looks
at source code).




这不是真的。 g ++将假设您的代码是C ++,而gcc将尝试从文件名中自动检测它。但是对于_linking_,g ++

会向C ++

代码所需的链接器命令行添加任何内容。

另一个问题是C ++ RTL。


什么是C ++ RTL?

这可能应该初始化,这取决于系统,可能是必要的,也可能不是必需的。最简单的解决方案是将
C main重命名为C_main,用C ++编写主要内容,只调用此C_main。



That''s not quite true. g++ will assume your code is C++, while gcc will
try to auto-detect it from the file name. For _linking_ however, g++
will add anything to the linker command line that is needed for C++
code to work.
Another issue is the C++ RTL.
What is a C++ RTL?
That probably should be initialised, which is system dependent and may
or may not be necessary. The easiest solution to this is to rename the
C main to C_main, write your main in C++ that only calls this C_main.




我不是看看为什么需要这样做。



I don''t see why this would be needed.


这篇关于从C访问C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆