从C调用C ++ [英] Calling C++ from C

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

问题描述

我正在尝试编写一些可由C调用的C ++库例程。

函数声明为externC。但我得到

加载器抱怨它无法解析new()和delete()。我是否只是缺少一个库或者是C ++运行时环境

也是一个问题?将C程序编译为C ++程序

似乎有用但我宁愿让库看起来像

a普通C库。


-

Joe Seigh

I''m trying to write some C++ library routines callable by C.
The functions are declared extern "C" but I''m getting the
loader complaining it can''t resolve new() and delete(). Am I
just missing a library or is the C++ runtime environment
also an issue? Compiling the C program as a C++ program
seems to work but I''d rather have the library look like
a plain C library.

--
Joe Seigh

推荐答案

" Joseph Seigh" < JS ******* @ xemaps.com>写道...
"Joseph Seigh" <js*******@xemaps.com> wrote...
我正在尝试编写一些可由C调用的C ++库例程。
函数声明为externC。但我得到了
加载器抱怨它无法解析new()和delete()。我是缺少一个库还是C ++运行时环境
也是一个问题?


运行时可能不是问题,但C ++库可能缺少
。如果你正在使用的是gcc / g ++,请尝试使用g ++进行链接。

将C程序编译为C ++程序
似乎有用但我宁愿拥有库看起来像是一个简单的C库。
I''m trying to write some C++ library routines callable by C.
The functions are declared extern "C" but I''m getting the
loader complaining it can''t resolve new() and delete(). Am I
just missing a library or is the C++ runtime environment
also an issue?
Run-time is probably not an issue, but a C++ library is probably
missing. If it''s gcc/g++ you''re using, try linking using g++.
Compiling the C program as a C++ program
seems to work but I''d rather have the library look like
a plain C library.




为什么?



Why?


1月19日星期三2005 20:31:59 -0500,Victor Bazarov< v。******** @ comAcast.net>写道:
On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote:
" Joseph Seigh" < JS ******* @ xemaps.com>写道...
"Joseph Seigh" <js*******@xemaps.com> wrote...


将C程序编译为C ++程序
似乎有用但我宁愿有库看起来像是一个简单的C库。
Compiling the C program as a C++ program
seems to work but I''d rather have the library look like
a plain C library.



为什么?



Why?



因此库可以有一个C api。用C ++编写它更容易

,因为我已经编写了C ++类来编写它。我可以

在伪对象C代码中重写C ++类但是考虑到C ++类是智能指针

类,那么
会非常繁琐。


-

Joe Seigh


So the library can have a C api. It''s easier to write it in C++
since I have the C++ classes to do it are already written. I could
rewrite the C++ classes in pseudo object oriented C code but that
would be pretty tedious considering the C++ classes are smart pointer
classes.

--
Joe Seigh


" Joseph Seigh" < JS ******* @ xemaps.com>写了...
"Joseph Seigh" <js*******@xemaps.com> wrote...
2005年1月19日星期三20:31:59 -0500,Victor Bazarov
< v。******** @ comAcast.net>写道:
On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov
<v.********@comAcast.net> wrote:
" Joseph Seigh" < JS ******* @ xemaps.com>写道...
"Joseph Seigh" <js*******@xemaps.com> wrote...


将C程序编译为C ++程序
似乎有用但我宁愿有库看起来像是一个简单的C库。
Compiling the C program as a C++ program
seems to work but I''d rather have the library look like
a plain C library.



为什么?



Why?


因此库可以有一个C api。用C ++编写它更容易,因为我已经编写了C ++类。我可以在面向伪对象的C代码中重写C ++类,但考虑到C ++类是智能指针类,这将是非常繁琐的。


So the library can have a C api. It''s easier to write it in C++
since I have the C++ classes to do it are already written. I could
rewrite the C++ classes in pseudo object oriented C code but that
would be pretty tedious considering the C++ classes are smart pointer
classes.



让我直截了当。该库具有C接口。但是由于你自己遇到同样的问题,因为你遇到了
(链接时缺少库),因此无法从C中使用
。因此,它只会在C ++项目/程序中有用。为什么不给它的用户

一个忙,把它留给C ++?



Let me get this straight. The library has a C interface. But it''ll
be impossible to use from C due to the same problem you yourself
encountered (missing libraries when linking). So, it will only be
useful within a C++ project/program. Why not do the users of it
a favour and leave it C++?


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

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