Last active
April 26, 2020 14:39
-
-
Save akiross/8381ec28b46651492e8a5b374667be0d to your computer and use it in GitHub Desktop.
Compile a C/C++ program without make, but using a simple header that is valid in both C/C++ and (ba)sh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
# Run this file with bash to compile the C++ program. | |
CC=g++ | |
FLAGS= | |
# Output file will have the same name of this file without extension | |
OUT_FILE=${BASH_SOURCE%.cpp} | |
# Ensure we are not overwriting | |
if [ -f "$OUT_FILE" ]; then | |
read -n 1 -p "File exists, overwrite? [y/N]" yn | |
case $yn in | |
[Yn]* ) echo;; | |
* ) exit;; | |
esac | |
fi | |
# Compile | |
echo "Compiling to $OUT_FILE" | |
$CC $BASH_SOURCE -o $OUT_FILE $FLAGS | |
exit | |
#endif | |
#include <iostream> | |
int main(int argc, char *argv[]) { | |
std::cout << "Hello, World!\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment