0

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.

4
  • Someone translate this for us? I'm not sure what exactly the question is. Commented Jan 5, 2011 at 13:52
  • 1
    From 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. Commented 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)? Commented Jan 5, 2011 at 13:58
  • 1
    As already noted, IDE != compiler != using an existing compiler. Please fix your terminology, that's very confusing. Commented Jan 5, 2011 at 14:17

2 Answers 2

2

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.

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

4 Comments

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
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.
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.
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.
0

GCC can only be invoked from a shell, for compiler functionality inside an IDE look at the libclang project:

http://llvm.org/devmtg/2010-11/Gregor-libclang.pdf

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.