• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

timholy/Cpp.jl: Utilities for calling C++ from Julia

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

timholy/Cpp.jl

开源软件地址:

https://github.com/timholy/Cpp.jl

开源编程语言:

Julia 100.0%

开源软件介绍:

Cpp.jl

Simple utilities for calling C++ from Julia

See also CxxWrap, Clang, and Cxx. CxxWrap is the recommended solution for calling C++ and supersedes this package.

Overview

Julia can call C code with no overhead, but it does not natively support C++. However, the C++ ABI is essentially "C plus some extra conventions," of which the most noteworthy is name mangling. Name mangling is used to support function overloading, a key C++ (and Julia) feature. Infamously, different compilers use different mangling conventions, and this has lead to more than a few headaches. However, in recent years there has been a greater push for standardization of the C++ ABI, and there is good documentation available on calling conventions of different compilers.

This package provides utilities to call functions in C++ shared libraries as if they were C. Currently it consists of a single macro, @cpp.

Installation

Install from the Julia prompt via Pkg.add("Cpp").

Usage

An example C++ shared library, libdemo, is provided in the deps directory. It contains the function timestwo, defined for two different C++ types:

 int timestwo(int x) {
   return 2*x;
 }

 double timestwo(double x) {
   return 2*x;
 }

Within Julia, let's suppose you've defined the variable libdemo to be a constant string containing the path to this library. You can use these functions by placing the @cpp macro prior to a ccall, for example:

 x = 3.5
 x2 = @cpp ccall((:timestwo, libdemo), Float64, (Float64,), x)
 y = 3
 y2 = @cpp ccall((:timestwo, libdemo), Int, (Int,), y)

The macro performs C++ ABI name-mangling, using the types of the parameters, to determine the correct library symbol. On a UNIX/gcc system, the first will generate a call to _Z8timestwod, and the second to _Z8timestwoi.

Limitations/TODO

Like ccall, this performs library calls without overhead. However, currently it has a number of limitations:

  • It does not support pure-header libraries
  • Using C++ objects has not been tested, and probably won't work without additional effort
  • Currently there is no C++ namespace support
  • Currently there is no support for templated functions
  • Currently only g++ is supported

The latter three may not be difficult to fix.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap