0

I'm working with GraalVM coding in Java and C++ as polyglot code. I have this code to print in C++ with Java:

printMessage.cpp C++ code:

#include <iostream>

int imprimemensaje(std::string s);

int main() {
    int imprimemensaje(std::string s);
    std::cout << "Hello, C++ World!" << std::endl;
    int a = imprimemensaje("Hola mundo c++");
}

int imprimemensaje(std::string s){
    std::cout << "Mensaje desde c++ : " << s << std::endl;
    return 0;
}

and this code in Java to execute C++ object using execute():

File file = new File("printMessage");
Source source = Source.newBuilder("llvm", file).build();    
Value cpart = context.eval(source);
cpart.execute();

And print on screen this:

Hello, C++ World! Mensaje desde c++ : Hola mundo c++

I need to call only imprimemensaje() function to send data from Java, I tried with cpart.getMember("IDmember") method, but it retrieves me a null value, also cpart.getMemberKeys() has no items on it.

Does anyone know why this happened or is there another way to send data to c++ object through Java? Thanks.

4

0 回答 0