Windows下,使用cxx.jl调用C++ dll有问题

参考官方文档的Example 8: Using C++ with shared libraries,由于例子是linux,我想改为Windows的dll形式。
https://github.com/JuliaInterop/Cxx.jl

头文件JuliaDll.h

#ifndef ARRAYMAKER_H
#define ARRAYMAKER_H

class __declspec(dllexport) ArrayMaker
{
private:
int iNumber;
float fNumber;
float* fArr;
public:
extern “C” __declspec(dllexport) ArrayMaker(int, float);
float* fillArr();
};

extern “C” __declspec(dllexport) double GetSum(double x, double y);

#endif

cpp文件JuliaDll.cpp

#include “JuliaDll.h”
#include <iostream>

using namespace std;

ArrayMaker::ArrayMaker(int iNum, float fNum) {
cout << "Got arguments: " << iNum << ", and " << fNum << endl;
iNumber = iNum;
fNumber = fNum;
fArr = new float[iNumber];
}

float* ArrayMaker::fillArr() {
cout << “Filling the array” << endl;
for (int i=0; i < iNumber; i++) {
fArr[i] = fNumber;
fNumber *= 2;
}
return fArr;
}

double GetSum(double x, double y)
{
return x + y;
}

参考例子导入库

julia> const path_to_lib = pwd()
addHeaderDir(path_to_lib, kind=C_System)
Libdl.dlopen(joinpath(path_to_lib, “JuliaDll.dll”), Libdl.RTLD_GLOBAL)
cxxinclude(joinpath(path_to_lib, “JuliaDll.h”))

调用这个导出为C接口的函数可行

julia> a = @cxx GetSum(1,2)
3.0

参照例子报错

julia> maker = @cxxnew ArrayMaker(5, 2.0)
LLVM ERROR: Program used external function ‘_ZN10ArrayMakerC1Eif’ which could not be resolved!

想请教一下是哪里不对

我以前尝试用这个包调用C++的时候也没有成功,原因是它已经不支持最近若干版本了:

Please, note that Cxx.jl only works (out of the box) currently with Julia 1.1.x to 1.3.x, i.e. with no currently supported Julia, while those versions can still be downloaded at Julialang.org.

维护人员遇到了关于LLVM的技术问题并不知道如何解决。不知你跑的是哪个版本?

我用的1.1.1,我用Cxx.jl可以调用extern "C"导出的函数,但是没法像给的例子那样使用类。

Windows的binarybuild是用mingw32工具链交叉编译的,我相信没有人在非cygwin或msys2环境下测试过调dll。从报错来看,可能用于编译你的dll库的编译器使用的mangling与Clang不同。

Cxx在Julia1.6+的复活工作正在进行,但目前请用CxxWrap.jl调C++。

好的,谢谢,我再研究下