-1

I am trying to build a Java application that compiles and runs C++ files. It also stores the output of the .exe file in a text file. Can anyone provide a complete walk through on how to do it?

I have already tried the solution provided here and the program showed compilation successful message. But I couldn't find the .o file or .exe file in the directory.

2
  • Show your code, not someone else's. Commented Oct 26, 2016 at 14:02
  • "Can anyone provide a complete walk through on how to do it ?" Such a question is WAY too broad for Stack Overflow. Commented Oct 26, 2016 at 14:02

2 Answers 2

1

General question -> General Answer

Easiest way to do it: Generate a makefile, run that.

For make see reference

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry, but with that level of simplicity, he will introduce far too few dependencies and the job will execute too fast.
1

This might not be a Java or a C++ problem. Are you certain your compiler is properly set up? What command are you using to invoke it? Assuming you are using the code provided here, are the paths indicated correct?

Process p = Runtime.getRuntime().exec("cmd /C gcc " + filename + " -o " + exeName, null, dir);

Try opening a command prompt and invoking the compiler by hand:

gcc Hello.cpp

Assuming the paths are correct for both the executable and the file, you either get an error, or a file named something like $a.exe in your working directory.

Lastly: I haven't used Mingw32 in a while, but you might need to call g++ instead of gcc for C++ code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.