Skip to content

Latest commit

 

History

History
99 lines (71 loc) · 2.42 KB

Running C++.md

File metadata and controls

99 lines (71 loc) · 2.42 KB

C++

Command Line (Mac)

Follow the instructions here. Step 4 might give errors but it should still install. After this, running the following command should display gcc.

gcc --version

The following command should also work.

brew install gcc

In this case, the g++ command will still default to clang, but you can substitute g++-8 instead.

Shortcuts

Open your bash profile with a text editor such as gedit.

brew install gedit
gedit ~/.bash_profile

Add the following functions.

co() { 
    g++ -std=c++17 -Ofast -Wall -Wl,-stack_size -Wl,0x10000000 -o $1 $1.cpp
}
run() {
    co $1 && ./$1
}

Now you can easily run C++ from the command line by calling run.

run [prog name]

Troubleshooting

Make sure you have installed XCode command line tools.

xcode-select --install
xcode-select --version
softwareupdate --list
softwareupdate -i -a

For OS X Mojave, navigate to your bash profile

gedit ~/.bash_profile

and add the following line:

export CPLUS_INCLUDE_PATH="/usr/local/include/c++/8.1.0/:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include:$CPLUS_INCLUDE_PATH"

IDE

Online

Local

Useful Links

Reference

Other