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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.