Results 1 to 7 of 7
  1. #1
    Ampzor is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Is it Possible to call C++ from Java?

    Like the title said, similar to Jython? Is it possible to do that?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Is it Possible to call C++ from Java?

    Read about JNI: Chapter 5: JNI Technology or how to use Runtime.exec()

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,514
    Blog Entries
    7
    Rep Power
    20

    Default Re: Is it Possible to call C++ from Java?

    You could also have a look at JNA (a third party library and Google is your friend); I never used it but it claims that you don't need those silly wrapper functions between Java and C/C++

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Is it Possible to call C++ from Java?

    Quote Originally Posted by JosAH View Post
    You could also have a look at JNA (a third party library and Google is your friend); I never used it but it claims that you don't need those silly wrapper functions between Java and C/C++
    With one caveat: JNA doesn't do C++, so you'd have to create a wrapper to translate the C++ to standard C calling convention.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,514
    Blog Entries
    7
    Rep Power
    20

    Default Re: Is it Possible to call C++ from Java?

    Quote Originally Posted by Fubarable View Post
    With one caveat: JNA doesn't do C++, so you'd have to create a wrapper to translate the C++ to standard C calling convention.
    Wouldn't solve a simple extern "C" { ... } solve that small inconvenience?

    kind regards,

    Jos

    ps. I never used JNA so I'm just guessing.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Is it Possible to call C++ from Java?

    Quote Originally Posted by JosAH View Post
    Wouldn't solve a simple extern "C" { ... } solve that small inconvenience?

    kind regards,

    Jos

    ps. I never used JNA so I'm just guessing.
    I think it would -- if you had the C source code, right? otherwise (I think) you'd need to write a wrapper.

    I've used JNA myself, but mainly to interface with the Windows dll's, especial user32.dll.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,514
    Blog Entries
    7
    Rep Power
    20

    Default Re: Is it Possible to call C++ from Java?

    Quote Originally Posted by Fubarable View Post
    I think it would -- if you had the C source code, right? otherwise (I think) you'd need to write a wrapper.

    I've used JNA myself, but mainly to interface with the Windows dll's, especial user32.dll.
    Ah, yes, I guess all bets are off without the sources ;-) You need a wrapper indeed. Thanks for the information.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. how to call Java Bean Ireport frm Java application
    By Prashant.surwade in forum Advanced Java
    Replies: 8
    Last Post: 05-06-2012, 03:39 PM
  2. call by value and call by reference in java
    By sandeepsai39 in forum New To Java
    Replies: 7
    Last Post: 08-12-2010, 11:03 AM
  3. call c++ exe from java applet
    By jojji in forum Java Applets
    Replies: 21
    Last Post: 07-29-2010, 01:47 AM
  4. how to call dll from java ??
    By Omarero in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 05:14 AM
  5. how to call a dll from java
    By katie in forum Advanced Java
    Replies: 3
    Last Post: 12-10-2007, 10:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •