Check Compiler Status

We’ve found that some students are facing issues where their compiler cannot find the STL headers (e.g. <iostream>).

You can check your compiler status by running the follow command, which generates a very simple sample program and attempts to compile it:

file=$(mktemp); echo "#include <iostream>" >> "$file.cpp" && echo "int main(){std::cout<<\"Hello World\"<<std::endl;}" >> "$file.cpp" && g++ "$file.cpp" -o "$file.out" && $file.out; rm $file $file.out $file.cpp

If this command does not print “Hello World”, your compiler is not working.

If your compiler gives you a header file not found error like the screenshot below, proceed through this page to attempt a fix. If you get a different error, please make a post on the class discussion board.


Determine Your Shell

In order to proceed with the fix, we need to determine which shell you’re using. Run the following command:

echo $SHELL

This will output a path to an executable. We are only concerned with the file (e.g. if the result is /my/folder/here/csh, we only care about csh).

  • If the result is bash, click here.
  • If the result is zsh, click here.
  • If the result is not present, please make a post on the class discussion board.

Fixing the Issue

The fix depends on which shell you’re using, we have separated out the steps by shell.

Fixing with bash

Run the following command:

echo "export CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1" >> ~/.bashrc

Then, run

touch ~/.bash_profile && cat ~/.bash_profile

This will read out the content of ~/.bash_profile. If it contains something about .bashrc, skip the next command.

If the file does not contain anything about .bashrc, run the following command:

echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile

Now click here to test and finalize the fix.

Fixing with zsh

Run the following command:

echo "export CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1" >> ~/.zshrc

Now click here to test and finalize the fix.


Finalizing the Fix

To finalize the fix, either restart your computer or log out and log back in.

Run the status check command and see if it is now working.

If it is still not working, please make a post on the class discussion board.

If it is working, please note the following:

This fix will stop working if you change shells (e.g. switch from bash to zsh). If you change shells, you must apply the fix to the new shell with the steps for that new shell.