I have an alias defined to compile an opencv program which goes like this
alias gcv='g++ -I/usr/local/include/opencv -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect'
Then I go on to type
gcv imageshow.cpp
I get this long list of errors
But when I use the same command specified in the alias with the .cpp(source code) file in between the Include and Library files (following the suggestion here), everything works like a charm.
g++ -I/usr/local/include/opencv imageshow.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui
Now typing the long command, which gets even bigger as complexity increases, every time is getting difficult, please help me in getting the alias to work or suggest any other alternative.
Try this without using aliases:
Why not use a simple script instead of the alias?
file
gcv
in~/bin/
Alternatively if you're using
zsh
you can use a function defined in your.zshrc
file:Automated compiler and linker flags
If you're having linker issues, you can also incorporate
pkg-config
here:Spaces in filenames
While other posts on similar issues exist, handling spaces in the filenames is not trivial so I thought I'd recap an elegant solution here; specifically I found that making use of the
IFS
variable helps tremendously.So making a small addition to end up with
solves issues with spaces in filenames too!
The post on creating a shell script wasn't very clear .. This was the simple procedure I followed to create a script of my own and it works even if the filename have spaces in it..
Here's what I did
mkdir ~/bin
nano ~/bin/gcv
sudo chmod u+x ~/bin/gcv
Type in the following into the script
export PATH=$PATH:~/bin
echo $PATH
and make sure u see~/bin
listed in the output u get.alais
if you see any aliases by the namegcv
use the commandunalias gcv
or else u'll have trouble usinggcv
as a command to compile the code, May be aliases have higher priority than scripts.