Refer to official documents Example 8: Using C++ with shared libraries,the example is on linux,but I want to test on windows.
https://github.com/JuliaInterop/Cxx.jl
JuliaDll.h
#ifndef ARRAYMAKER_H
#define ARRAYMAKER_Hclass __declspec(dllexport) ArrayMaker
{
private:
int iNumber;
float fNumber;
float* fArr;
public:
ArrayMaker(int, float);
float* fillArr();
};extern “C” __declspec(dllexport) double GetSum(double x, double y);
#endif
JuliaDll.cpp
#include “JuliaDll.h”
#includeusing 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;
}
Refer to that example
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”))
This function is right
julia> a = @cxx GetSum(1,2)
3.0
Copy the example’s code report an error
julia> maker = @cxxnew ArrayMaker(5, 2.0)
LLVM ERROR: Program used external function ‘_ZN10ArrayMakerC1Eif’ which could not be resolved!