Compiling C++-code without a file

前端 未结 5 1670
无人及你
无人及你 2020-12-10 20:34

I\'m trying to compile some C++ code using your standard g++ compiler. However, rather than compiling from a file:

main.cpp:

#include 

        
5条回答
  •  孤城傲影
    2020-12-10 20:59

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

    works but I would like to know how it works and better yet, if there is a way to do this without the need to pipe the contents.

    Alternatively you can say (e.g. in a shell-script):

    gcc -Wall -o testbinary -xc++ - << EOF
    int main(){}
    EOF
    

提交回复
热议问题