使用C库为C ++程序 [英] Using C Libraries for C++ Programs

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

问题描述

我试图用控制使用Qt的GUI做Dynamixel舵机。 Dynamixel提供了账套 C库来控制电机,同时使GUI的唯一途径我所知道的是Qt的,这基本上是C ++。将有可能以任何方式使用Dynamixel C库从Qt的C ++ code?

I am trying to control Dynamixel servos using a GUI made using Qt. Dynamixel provides a C set of C libraries to control the motors, while the only way of making GUI's I know is Qt, which is essentially C++. Will it be possible to use Dynamixel C libraries from Qt C++ code in any way?

推荐答案

是的,C ++可以编译C与C ++编译器,你可以链接C ++对C.只要确保你调用任何C函数使用C链接。这使我的封闭的由的externC

Yes, C++ can compile C with a C++ compiler and you can link C++ against C. Just be sure that any C function you call uses C linkage. This is made my enclosing the prototype of by an extern "C"

#ifdef __cplusplus
extern "C"{
#endif 

void c_function_prototype();

#ifdef __cplusplus
}
#endif

该库的头可能已经做到这一点,顺便说一句。

The headers for the library may already do that, BTW.

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

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