Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:46:03+00:00 2026-06-01T03:46:03+00:00

I am learning OpenCV using Learning OpenCV book. One problem I am facing while

  • 0

I am learning OpenCV using Learning OpenCV book.

One problem I am facing while compiling the code is that I have to write a long command to compile and get the executable.

This is the command I am using

g++ `pkg-config –cflags opencv` file_name.cpp -o output_file `pkg-config –libs opencv`

I am no Make expert but I think I can eliminate writing that long command using make.
Before that I should explain my work flow. I have created a directory called opencv in my home directory (~/opencv/). I am reading the book section by section and coding the examples or exercises into new cpp source code files in that directory. So I don’t know the names of the files before hand.

Now what I want make to do is,

Suppose I have coded a new file named facedetect.cpp in my opencv directory, and if I call make like this

make facedetect

then I want make to execute the following command for me

g++ `pkg-config --cflags opencv` facedetect.cpp -o facedetect `pkg-config --libs opencv`

so that whenever I make a new file named abc.cpp, I will execute make abc
so that I can run

$ ./abc

at my command line to test my abc.cpp

Please give that make file so that I can save the frustration of typing that long command each time.

PS: I have Googled for help on this and found this on using CMake but I could not understand what that does. Kindly also explain how can I use CMake for the same task.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:46:04+00:00Added an answer on June 1, 2026 at 3:46 am

    You can create a file called Makefile in you working directory like this:

    CFLAGS = `pkg-config --cflags opencv`
    LIBS = `pkg-config --libs opencv`
    
    % : %.cpp
            g++ $(CFLAGS) $(LIBS) -o $@ $<
    

    then you can use this file for all your single-file programms. Just call make with the basename of the file you want to compile. For facedetect.cpp that would be

    make facedetect
    

    Here some more details:

    The general format of a makefile is like this:

    target : dependecy1 dependenc2 ...
        command that generates the target
    

    So for your example you could write:

    facedetect : facedetect.cpp
        g++  $(CFLAGS) $(LIBS) -o facedetect facedetect.cpp
    

    For each new example you can now create a new target. But you can also make it more general:

    % : %.cpp
        g++  $(CFLAGS) $(LIBS) -o $@ $<
    

    Here % matches any nonempty substring. The automatic variables $@ and $< substitute the names of the target file and the source file.
    For more information you can consult the make documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to code an object detector (in this case, a ball) using OpenCV.
I've picked up 'Learning OpenCV' and have been trying some of the code examples/exercises.
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
In the Learning OpenCV book: . . CvCapture *capture = cvCreateFileCapture(argv[1]); IplImage* frame; while(1)
Learning Objective-C and reading sample code, I notice that objects are usually created using
I am working through the book Learning OpenCV from the O'Reilly series and am
The Oreilly book Learning OpenCV states at page 356 : Quote Before we get
Learning jquery, so please be kind :) Using PHP, I have a table with
learning Jquery and integrating with PHP - getting there, but have one last challenge
In a program in the Learning OpenCV book: void onTrackbarSlide(int pos) { cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.