This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c/c++ from Java

 
Swapnil Sanghai
Ranch Hand
Posts: 41
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to run c/c++ code from Java program.
 
Tim Moores
Bartender
Pie
Posts: 2496
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am certain that this is not part of the SCWCD certification (which this forum is all about)

The JNI API can be used to call C/C++ code from Java.
 
Swapnil Sanghai
Ranch Hand
Posts: 41
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used the JNI but it shows me an error as can't find the class file. Means when I compile the .java file it creates the .class file with no error or exception but when I try to make the header file using "javah" it is telling that he couldn't find the required class file. I placed .java and .class file in the same directory.
 
Tim Moores
Bartender
Pie
Posts: 2496
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to work through a JNI introduction like http://www.ibm.com/developerworks/java/tutorials/j-jni/ or http://www.javaworld.com/javaworld/jw-10-1999/jw-10-jni.html. After that, things should become clearer.

PS: Strange URL of this topic: ".../java/java/java". SEO at work?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Runtime.exec("C:\\Programs\\MyCPlusPlusProgram.exe");
 
Swapnil Sanghai
Ranch Hand
Posts: 41
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jimmy. Thanks everyone.
 
Swapnil Sanghai
Ranch Hand
Posts: 41
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jimmy:
When I run the code using the Runtime object as you said it gives me error telling that


C:\WINDOWS\system32\ntvdm.exe
Error while setting up environment for application. Choose close to terminate the application.

I am running the program on windows XP and I used TC compiler for the C program. Please tell me what is the cause.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic