A am using below command to compile my c++ code and which is using OpenCV libraries and my command is just like
opencv main.cpp -o binary_name
where opencv is an alias command like
alias opencv="g++ `pkg-config --cflags opencv` `pkg-config --libs opencv`"
but if I forget the “-o binary_name” the command delete my source file. Why this happening….?
What modification should I made on the above alias command to compile my source file like
opencv main.cpp binary_name
Thanks in advance…….
The order of arguments to
gccis important, source or object files should be given before libraries, and libraries should be invoked with higher level libraries before the lower level libraries they are using.So you should compile with
But you really should use a
Makefile, or at least have a shellscript.Don’t forget the
-Walloption to get all warnings. Improve your code till no warnings are given by the compiler. Use the-goption to get debugging information, to be able to usegdb ./binaryprogto debug your program.Once your program is debugged, replace
-gby-O3(or perhaps by-O2 -g) to ask GCC to optimize the generated code.