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,641
    Rep Power
    8

    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 offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,183
    Blog Entries
    7
    Rep Power
    24

    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
    The only person who got everything done by Friday was Robinson Crusoe.

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

    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 offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,183
    Blog Entries
    7
    Rep Power
    24

    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.
    The only person who got everything done by Friday was Robinson Crusoe.

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

    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 offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,183
    Blog Entries
    7
    Rep Power
    24

    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
    The only person who got everything done by Friday was Robinson Crusoe.

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, 06:14 AM
  5. how to call a dll from java
    By katie in forum Advanced Java
    Replies: 3
    Last Post: 12-10-2007, 11: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
  •