Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: calling c code from java

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Thanked 0 Times in 0 Posts

    Default calling c code from java

    hello everyone
    I hope that someone can help me
    I have tried to run c code in java using Runtime but I got the following error:
    Debug assertion failed
    althogh the c code is working correctly using visual c++ 6.0 and does not generate error and I'm able to run it using dll but I'm unable to run it using java

    Hlppppppppppppppp please
    thanks in advance

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: calling c code from java

    First guess is that the c code you are running is missing some sort of input (say perhaps a command line argument that specifies the file name to write to for the fprintf call?), but without further info there's no way to be sure. Can you provide a bit more info (eg code)? Are you using Runtime.exec? Have you provided all command line arguments necessary?

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Default Re: calling c code from java

    In simple terms, just make sure you load the relevant library which contains the function definition, load the library which follows the JNI specification and wraps the target function from the first library, expose native methods from your Java class and you should be good to go.

    I'd recommend against raw JNI since it contains a lot of boilerplate code and you would end up cursing yourself if you start wrapping a big C library. By all means do feel free to dabble in JNI when starting out but use something like JNA when it comes to real work.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: calling c code from java

    @nicz17: This is an ancient thread and what you copy/pasted off the internet is not more than others could have found for themselves.

    Please don't resurrect old threads, especially when you have no opinion of your own to add. It's annoying.

Similar Threads

  1. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM
  2. Convert C/C++ code to Java
    By cristianll in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 14th, 2009, 02:43 AM
  3. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM
  4. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 12:55 AM
  5. [SOLVED] How to call string in another class in java?
    By tazjaime in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 23rd, 2009, 09:31 AM