简体   繁体   English

是否有不支持使用C ++库的高级语言?

[英]Are there any high level language that don't support using C++ libraries?

是否有不支持使用C ++库的高级语言?

Using C++ libraries from other high-level languages has a couple of major obstacles: 使用其他高级语言的C ++库有两个主要障碍:

  • if the library is OO, you need to be able to create a C++ object in the calling language - this is not easy. 如果库是OO,则需要能够使用调用语言创建C ++对象-这并不容易。

  • C++ implementations use a technique known as "name-mangling" to ensure type-safe linkage. C ++实现使用一种称为“名称处理”的技术来确保类型安全的链接。 Unfortunately, there is no standard for name mangling, so C++ code cannot even easily be called between different C++ implementations. 不幸的是,名称修饰没有标准,因此在不同的C ++实现之间甚至不容易调用C ++代码。

So the answer to your question is that most HLLs will have problems calling C++ code. 因此,您的问题的答案是,大多数HLL都会在调用C ++代码时遇到问题。 They may also have problems calling any other language of course - there are actually no standardised binary interfaces between languages, except ad hoc, platform-specifc ones. 他们当然也可能在调用任何其他语言时遇到问题-除了即席的,平台特定的语言之外,语言之间实际上没有标准化的二进制接口。

I can't think of any language that is able to use C++ libraries directly. 我想不出任何能够直接使用C ++库的语言。 Even getting C++ to do it can be tricky (if the library was compiled with a different compiler than you're using) 即使使用C ++进行操作也可能很棘手(如果该库是使用与您使用的编译器不同的编译器进行编译的)

Of course, if you write a wrapper of some kind (either a wrapper for the specific library, or some kind of bindings library that lets you expose specific types), then any language can use C++ libraries. 当然,如果您编写某种包装器(用于特定库的包装器或用于公开特定类型的某种绑定库),则任何语言都可以使用C ++库。 But directly, as-is, with no extra work? 但是直接按原样进行,无需任何额外工作? I don't think any language other than C++ can do it. 我认为除C ++之外,没有其他语言可以做到这一点。

这有点反面,但是许多流行的高级语言可以通过swig( http://swig.org/ )绑定到为其创建的C ++库代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM