Also, ich brauche ein Skript, das eine Filepath als Eingabe nimmt und kompiliert & den Code ausführt (entweder C, C++, oder Ziel-C).Execute C/C++/Objective-C-Code-Datei über BASH-Skript (auf Mac OS X)
Ich gebe zu, ich bin kein BASH-Guru ... Also, gibt es einen besseren Weg, es zu tun? Was würden Sie ändern (und warum)?
Hier ist mein Code ...
C
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.c"
cp $input $newinput
gcc $newinput -o $output -std=c99
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "gcc :: Compiler Not found"
fi
exit $status
C++
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.cpp"
cp $input $newinput
g++ $newinput -o $output
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "g++ :: Compiler Not found"
fi
exit $status
Objective-C
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.m"
cp $input $newinput
clang $newinput -o $output -ObjC -std=c99 -framework Foundation
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "gcc :: Compiler Not found"
fi
exit $status