Compile data stream in C?

Is it possible to compile a data stream rather than compiling a .c file with gcc? for example, is it possible that instead of xyz.c my code in any xyz.c file, I can directly compile the code?

+6
source share
3 answers

Use the gcc options -x and -

  $ echo -e '#include <stdio.h> \ nmain () {puts ("Hello world"); return 0;}' |  gcc -xc -ogarbage - && ./garbage && rm garbage
 Hello world

The one line above consists of the following parts:

  echo -e '#include <stdio.h> \ nmain () {puts ("Hello world"); return 0;}' # "source"
 |  # pipe
 gcc -xc -ogarbage - # compile
 && # and
 ./garbage # run
 && # and
 rm garbage # delete
+8
source

You can create a file, pass code to it, and then create another process (that is, a compiler) by providing it with a file as an argument. Then create another process (i.e. the linker) and it will create an exe for you. And finally, you can run this exe as a new process. But why?!:)

+1
source

Source: https://habr.com/ru/post/892241/


All Articles