How to compile and run C/C++ in a Unix console/Mac terminal?

前端 未结 16 1595
抹茶落季
抹茶落季 2020-11-30 16:32

How can I compile/run C or C++ in Unix console or a Mac terminal?

(I know it, forget it, and relearn it again. Time to write it down.)

16条回答
  •  自闭症患者
    2020-11-30 16:41

    For running c++ files run below command, Assuming file name is "main.cpp"

    1.Compile to make object file from c++ file.

    g++ -c main.cpp -o main.o
    

    2.Since #include does not support in MacOS so we should use its alternative which supports in Mac that is #include . Now object file needs to be converted to executable file. To use curses.h we have to use library -lcurses.

    g++ -o main main.o -lcurses
    

    3.Now run the executable.

    ./main
    

提交回复
热议问题