Pipe file contents in g++ to compile

社会主义新天地 提交于 2019-12-23 23:38:33

问题


Is it possible to pipe the contents of a file into g++ to compile a program?

I want to do this because I want to use a file from a database rather than a physical file on a disk. The file contents can be easily retrieved via an API I have made.

For instance, I would like to do something like:

g++ contents_of_file -o executable

Thanks a lot.

Sam.


回答1:


Yes, you can pipe to gcc if you specify the language using the -x option;

echo "int main(){}" | gcc -Wall -o testbinary -xc++ -



回答2:


more fun:

alias true="gcc -xc++<(echo 'main()<%int(*)(int*)=6 "\?"<[:0:>;%>')&&a.out"

hey, works for me.



来源:https://stackoverflow.com/questions/16131984/pipe-file-contents-in-g-to-compile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!