Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Anyone knows a solution that works something like this: #include <stdio.h> #incl

ID: 654293 • Letter: A

Question

Anyone knows a solution that works something like this:

#include <stdio.h>
#include <gcc.h> /* This .h is what I'm looking for. */

int main (void) {
    /* variables declaration (...) */

    /* The following line is supposed to be equivalent to:
     *     $ gcc main.c -o main */
    results = gcc_compile_and_link("main.c", "main");

    /* Now I want to use the warnings and errors to do something.
     * For instance, I'll print them to the console: */
    printf("warnings: ");
    for (i=0; i<results.warns_len; i++)
        printf("%s ", results.warings[i].msg);
    printf("errors ");
    for (i=0; i<results.errs_len; i++)
        printf("%s ", results.errors[i].msg);

    /* free memory and finalize (...) */
    return 0;
}
I know I can run the command "gcc main.c -o main" in a fork and parse the output... but I was looking for something more 'reliable' like the example above.

Explanation / Answer

GCC was explicitly designed to resist being used as a tools base/library. You need to use Clang for this, or call GCC through commandline.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote