How to compile C++ under Ubuntu Linux?

前端 未结 11 1913
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 08:35

I cut&pasted the below code from a previous question into a file called \"avishay.cpp\" and then ran

gcc avishay.cpp

only to get the f

11条回答
  •  无人及你
    2020-12-09 09:04

    To compile source.cpp, run

    g++ source.cpp
    

    This command will compile source.cpp to file a.out in the same directory. To run the compiled file, run

    ./a.out
    

    If you compile another source file, with g++ source2.cpp, the new compiled file a.out will overwrite the a.out generated with source.cpp

    If you want to compile source.cpp to a specific file, say compiledfile, run

    g++ source.cpp -o compiledfile
    

    or

    g++ -o compiledfile source.cpp
    

    This will create the compiledfile which is the compiled binary file. to run the compiledfile, run

    ./compiledfile
    

    If g++ is not in your $PATH, replace g++ with /usr/bin/g++.

提交回复
热议问题