Skip to content

Add example of C++ calling into Java #35

@MarkDrei

Description

@MarkDrei

Not sure if this the right repository.
I am looking for an example how GraalVM is used to execute C/C++ code compiled to LLVM Bitcode which then interacts with Java. The basic example from https://www.graalvm.org/latest/reference-manual/polyglot-programming/ "Start Language C" is working for me, however this only creates an array and does not interact with any custom classes.
I would like to use a class that is implemented in Java, however I fail to make this work even with a basic example. I currently get errors like this
"Access to host class graalvm.polyglot.PolyglotTestClass is not allowed or does not exist."
and I don't know whether this is due to my command line setup (classpath?) or whether I am missing some imports in my C++ code or whether I am having some other issue.
Therefore it would really help me, and hopefully others, if such an example was added here.

Update: When I run the same C code not via lli but load it from a Java class that runs inside a GraalVM, then my C code succeeds to load the Java file.
To make this more clear:
GraalVM's lli running C code which tries load a Java class -> fails. Java class is not found.
GraalVM's java running a Java class which loads the C code above -> this works.

Thanks and best regards,
Mark

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions