I want write simple C IDE,I wrote some parts of it. It can check syntax of C,now I need to link my program to gcc,to make executable file. Now my program can get what you have entered ,then save it in any format(like notepad) Now I want to say g++ to make executable file,how can I do it? (For E.g) when user save his/her file then type 'compile it' in my program ,g++ do it and save executable file where program want or shows errors. How can I do it? I want to program it for Windows OS.
- Someone translate this for us? I'm not sure what exactly the question is.cHao– cHao2011-01-05 13:52:35 +00:00Commented Jan 5, 2011 at 13:52
- 1From your description you are not writing a compiler, but a gcc-wrapper. It is not clear though what language or platform you are using, this information might help others helping you.Itamar Katz– Itamar Katz2011-01-05 13:53:09 +00:00Commented Jan 5, 2011 at 13:53
- Are you writing a compiler (takes a C file, produces an EXE file) or an IDE (like Notepad, allows to write C file, then calls gcc to convert it to EXE)?Vilx-– Vilx-2011-01-05 13:58:08 +00:00Commented Jan 5, 2011 at 13:58
- 1As already noted, IDE != compiler != using an existing compiler. Please fix your terminology, that's very confusing.user395760– user3957602011-01-05 14:17:10 +00:00Commented Jan 5, 2011 at 14:17
Add a comment |
2 Answers
You don't need to "link" to gcc, instead you will invoke it in a sub-process. This is generally done using fork() and exec(), supplying the full command line to gcc so it knows what to compile, how to compile it and where to store the object or executable file result.
You don't mention your Operating System, but as you mentioned gcc I will assume Linux; have a look at this tutorial, but there many more out there.
4 Comments
Moein Hosseini
Thanks for your answer,I think it's so good for start,but what should I do for windows,I'm trying to program it in windows,anyway thanks
trojanfoe
Ah OK, I'm not too sure when using cygwin? - It might provide the fork()/exec() calls for you to use. If you were using the Microsoft Compilers (which are free with the WinSDK, BTW) then you'd use the Win32 API call CreateProcess() family of calls.
trojanfoe
Of CreateProcess()? Here's one from the internet: daycounter.com/LabBook/Windows-CreateProcess.phtml. However if you are using gcc then I'm not sure if CreateProcess() is correct - cygwin is an unconventional environment to say the least.
cHao
Cygwin does indeed provide a half-assed fork(). However, it's slow and clunky, and since Windows doesn't fork natively, there's some trickery involved (and probably some gotchas). CreateProcess(...) would be better in a Windows app.
GCC can only be invoked from a shell, for compiler functionality inside an IDE look at the libclang project: