kgrimes2 kgrimes2 - 3 months ago 7
C++ Question

Compiling C++ Program from Mac Command Line

I have 3 files: main.cpp, myheader.h, and myheader.cpp.

I would like to compile and execute main from the command line, but I am not sure how to go about this.

Any help would be appreciated.

Thanks

Answer

For anyone interested, one of the ways to compile a program is as follows:

g++ -o executableName main.cpp myheader.cpp -std=c++11

You may or may not need the flag at the end.

If you have other cpp files that need to be compiled, just add them where "myheader.cpp" is.

Once your executable has been created, you can run it with

./executableName
Comments