How to compile C++ console application in Ubuntu

I have done a simple console application made in C++. It uses OpenCV (last version) to detect the face in a given image. Now I want to compile this application in Ubuntu. I have seen several pages to do that (using cmake, g++...) but I don't know exactly the case to compile a entire project (not a simple .cpp). I want to know how to do that. Is there any tutorial for this?

Thanks!

Answers


This link presents a good example along with screenshots that would help you compile your basic openCV code.

Basically, whichever way you choose to compile, you would have to mention the path to openCV files.

When you use terminal to compile you will use an option similar to the one below:

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching

If there are multiple files that you intend to compile, you can include them in place of main.cpp in the above command.

The locations after -I provide location for the header files. -o option is used to set the name of the output binary file. You further explore the significance of other options in g++ command.

You would only have to modify the path in the above command while using it for your applications.

If you have a larger application, then writing a makefile or using cmake would make sense. Use of IDEs like Eclipse or CodeBlocks can also simplify things to some extent.

Further expanding your question would give a better understanding of your requirements.


You don't tell anything about your application. What size is it (ten thousand source lines)? How many files? Is it free software? With what license? Where is the code?

You probably should write a Makefile (if you don't have one) or some other way to build it (you might use, but I don't recommend for small projects, a Makefile generator like e.g. cmake or automake ...); see this

And you should probably have a README file documenting a little bit your application and how to build it.

Look (at least for inspiration...) into the source code of some existing free software similar to yours.

Also, don't forget to compile with all warnings & debug info (e.g. g++ -Wall -Wextra -g if using GCC, and perhaps also -std=c++11 if you code in C++11)


Need Your Help

Why do these parameters not work?

c# nullable out

public static string ChangeDeviceState(int deviceID, DeviceState nextState)

interview questions on sed or awk

awk sed

Hi I recently crashed and burned on a interview question on file editing. Kinda been bugging me. I searched on the forum but did quite get it to go.