在 C 中编译数据流?

标签 c stream compilation

是否可以使用 gcc 编译数据流而不是编译 .c 文件?例如,是否可以直接编译代码而不是将我的代码存储在任何 xyz.c 文件中?

最佳答案

使用 gcc 选项 -x-

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

上面的单行命令由以下部分组成:

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

关于在 C 中编译数据流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612169/

相关文章:

c++ - libiconv - iconv_open() 默认行为?

c - C 中的整数提升会降级 `long int` 吗?

c - 从一棵空树开始,用大 O 表示法插入红黑树的复杂度是多少?

c# stdin read没有响应

dart - 如何将 future 结果与 flutter 中的流连接起来?

c - 为什么在 gdb 中调用 calloc 似乎不会将内存归零?

node.js - 使用 Node.js 提取 .bz2 管道?

c++ - 是否需要 LD_LIBRARY_PATH(linux) 或 DYLD_LIBRARY_PATH mac

compilation - 如何在编译环境中使用鸡蛋?

c++ - 英特尔编译器 - 错误 : identifier "alignof" is undefined