0

I have installed opencv 2.4.2 on ubuntu 12.04.I want to know how do i compile an opencv program written in c++ in ubuntu?Also,what are the benefits of using a 'make file'?And how can i compile using make-file?

2 Answers 2

3

A makefile is a simple way of compiling a project without having to specify the compilation and linking instructions each time. It is constructed as a series of rules in the format:

target:dependencies
[tab] rule

where the rule must be prefixed with a tab.

For instance if you had a project which consisted of 2 source files, main.cpp and functions.cpp both of which used opencv code your makefile might consist of something like this:

executable: main.o functions.o
g++ -o executable `pkg-config --libs opencv` main.o functions.o

main.o: 
g++ `pkg-config --cflags opencv` -c main.cpp 

functions.o:
g++ `pkg-config --cflags opencv` -c functions.cpp

where main.cpp is just your main function in which you make several calls to functions defined inside functions.cpp. The instruction pkg-config --cflags/libs opencv uses a utility called pkg-config which automatically generates the necessary compiler and linker flags, paths and libraries needed for building. You can of course specify these manually in your makefile if the library you are using does not support pkg-config but as opencv does, it makes sense to use it.

To compile using a makefile you simply naviage to the directory where you have saved your source code, save the makefile as 'Makefile' and build with the command make.

Sign up to request clarification or add additional context in comments.

Comments

0

This is a general tip:

You can use eclipse IDE to accelerate your development.

Here is a post that explains how to get this done easily:

http://codewithgeeks.blogspot.in/2013/10/installing-opencv-ubuntu-1204-eclipse.html

and

http://codewithgeeks.blogspot.in/2013/10/installing-opencv-ubuntu-1204-eclipse_10.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.