简体   繁体   中英

C++ to Java(openmp)

I'd appreciate it if you could help on this

Basically what I need to do is to find the best way to load a cpp file through java.

Explaining more, I have a program written in C++ (openmp) and I need to write a Java Gui that will run this file along with some other tasks.

What is the most efficient and easier way to do this? Do you have any online books, or recommendations for it?

Also could this be done through xml? I mean have the xml structure and load the java's gui file and then the.cpp? How could this work?

Thanks

I think what you are looking for is the JNI: http://en.wikipedia.org/wiki/Java_Native_Interface

Search the web for "JNI getting started" or "JNI tutorial" or "JNI Hello World".

Take a look at Runtime.getRuntime().exec(String); . This method invokes another application. Here is some example usage:

public void runBtnActionPerformed(ActionEvent evt)
{
    try {
        Process p = Runtime.getRuntime().exec("./mycppapp"); // or for Windows "mycppapp.exe"
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = null;
        while ((line = br.readLine()) != null)
        {
            System.out.println(line);
        }
    } catch (Exception e)
    {
        // handle here
    }
}

Be sure you compiled your C++ application. It is impossible to run the code without compilation. You can try to compile the C++ through Java, using the same method:

int success = Runtime.getRuntime().exec(new String[]{"g++", "mycode.cpp"}).waitFor();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM