Skip to content

Instantly share code, notes, and snippets.

@gavincangan
Created September 3, 2018 23:31
Show Gist options
  • Save gavincangan/bb98579e7e88d31cf4849a641406e5d2 to your computer and use it in GitHub Desktop.
Save gavincangan/bb98579e7e88d31cf4849a641406e5d2 to your computer and use it in GitHub Desktop.
Build and run a C++ file using g++
#!/bin/bash
cpp_file_to_build=$1
output_file=$(pwd)/${cpp_file_to_build/\.cpp/\.o}
rename_output_file=$(pwd)/zz_${cpp_file_to_build/\.cpp/\.o}ld
mv $output_file $rename_output_file
g++ -std=gnu++11 -Wall $cpp_file_to_build -o $output_file;
if [ -f $output_file ]; then
$output_file
else
echo Output binary not found! Build must have failed!
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment