Thread: Running GCC from within my program

  1. #1

    Running GCC from within my program

    Hello all. I am writing a program to be a sort of gcc/g++ frontend. OF course, to do this, i need to be able to run gcc and/or g++. I also need to be able to capture the output and the return value of it, so i can determine whether i have to show the user the errors, or whether it exited ok.

    I don't know of any ways to capture the output, thats why I am asking, but i was thinking this: I could have it > to a file, and then read tha, if all else fails... Tell me what you think, if the other isn't a possibility. Thanks in advance.

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Wow. I had no idea it would be that easy. I'm still waiting for my shell account to be activated (cause idon't currently have a working linux) but that looks simple enough to work. Man, you are like the god of the forum...

    Thanks!

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  3. #3

    this is interesting... but annoying...

    Everything works except this one part:
    Code:
    (newdecad@grex:~/prog)$ g++ -o epile epile.cpp
    epile.cpp: In function `int main(int, char **)':
    epile.cpp:85: implicit declaration of function `int pclose(...)'
    Any ideas?

    Code:
      79:           fGcc = popen( sCompileString, "r" );
      80:           if( fGcc ) { 
      81:                   iGccBufLine = 0;
      82:                   while( fgets( sGccBuf[iGccBufLine], 128, fGcc ) ) {
      83:                           printf( "%s", sGccBuf[iGccBufLine++] );
      84:                   }
      85:                   printf( "%d\n", pclose( fGcc ) );
      86:           }
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  4. #4
    Do you think it matters that i am using g++ and
    Code:
    #include <cstdio>
    ?

    ~inquirer

    [EDIT/] STill didn't work, trying prototyping


    [EDIT] That doesn't seem to work either:
    Code:
    (newdecad@grex:~)$ g++ -o epile epile.cpp
    ld: Undefined symbol 
       pclose(_iobuf *)   
    collect2: ld returned 2 exit status
    [/EDIT]
    Last edited by Inquirer; 04-07-2003 at 03:17 PM.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stop program from running twice?
    By Abda92 in forum C Programming
    Replies: 19
    Last Post: 03-17-2008, 01:35 PM
  2. Running program in unix
    By Cpro in forum Linux Programming
    Replies: 2
    Last Post: 02-10-2008, 09:28 PM
  3. Replies: 3
    Last Post: 09-05-2005, 08:57 AM
  4. Why is my program running away?
    By badkitty in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2001, 04:27 PM
  5. Running program
    By muffin in forum C Programming
    Replies: 5
    Last Post: 08-30-2001, 10:57 AM