Please see Call functions in other files in C++ and OpenCV for initial problem. The code I am using is given there in detail. This is a subproblem.
I have a BASH script:
echo "compiling $1"
if [[ $1 == *.c ]]
then
gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`;
elif [[ $1 == *.cpp ]]
then
g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;
else
echo "Please compile only .c or .cpp files"
fi
echo "Output file => ${1%.*}"
The above BASH script is used to compile OpenCV code using ./script.sh input.cpp
.
My doubt is how can I modify it to compile multiple files at the same time, like another file with some functions I am using in my main code like:
./script.sh input.cpp functions.cpp
EDIT
As suggested by John B, I modified my BASH script to
for f in "$@"; do
echo "compiling $f"
if [[ $f == *.c ]]
then
gcc -ggdb `pkg-config --cflags opencv` -o `basename "$f" .c` "$f" `pkg-config --libs opencv`
elif [[ $f == *.cpp ]]
then
g++ -ggdb `pkg-config --cflags opencv` -o `basename "$f" .cpp` "$f" `pkg-config --libs opencv`
else
echo "$f is not .c or .cpp file"
fi
echo "Output file => ${f%.*}"
done
But now, I get the following error:
compiling draw_shapes.cpp
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Output file => draw_shapes
compiling test.cpp
/tmp/ccW65wuP.o: In function `main':
/home/kanishka/Desktop/opencv test/test.cpp:31: undefined reference to `draw_line(cv::Mat, cv::Point_<int>, cv::Point_<int>, int, int, int)'
collect2: error: ld returned 1 exit status
Output file => test