GraalVM 多语言:将参数从 Java 传递到 LLVM (C++)

问题描述

the docs 之后,我可以运行 Polyglot 应用程序,其中起始语言是 Java,目标语言是 C++,它位于单独的源文件中。

我想知道如何将一些参数从 Java 传递给 C++。

代码示例

开始语言(Java)

import org.graalvm.polyglot.*;
import java.io.File;
import java.io.IOException;

public class HelloPolyglot {
    public static void main(String[] args) throws IOException {
        File file = new File("polyglot"); // the path to the file
        Source source = Source.newBuilder("llvm",file).build();

        Context polyglot = Context.newBuilder().allowAllAccess(true).build();

        Value cpart = polyglot.eval(source);
        cpart.executeVoid();
    }
}

目标语言(C++)

#include <iostream>
using namespace std;
  
int main(int argc,char** argv){
    cout << "You have entered " << argc
         << " arguments:" << "\n";
  
    for (int i = 0; i < argc; ++i)
        cout << argv[i] << "\n";
  
    return 0;
}

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)