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 7972241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:48:47+00:00 2026-06-04T07:48:47+00:00

I have been searching but could not find something clear for my doubt. I

  • 0

I have been searching but could not find something clear for my doubt.

I am trying to define my own class in c++, my class uses the libraries from opencv.

I create a file.h file where I just declare the functions, with its guards.

I create a file.cpp file where I explain how the functions look like. In this program I used all the includes I would use in a normal opencv program. (I thought it was right) + the include file.h.

Normally I compile my opencv programs like:

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

Now I try to compile my file.cpp by the same way in order to use the class in oder main file but I obtain an error.

The next step, once I would have the compiled class would be:

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

Any help/advice would be nice since it is the first time I am managing with such a big program.

#ifndef _NAMES_H  
#define _NAMES_H     

class segmentator {
public:
      
   void search(Mat img,
               vector<std::vector<cv::Point> >&contours,
               vector<int>&similarity);
   
   void similar(vector<std::vector<cv::Point> >&contours,
                vector<std::vector<cv::Point> >&contours2,
                vector<int>&similarity);
   
   vector<Mat*> separate(Mat img,
                         Mat img2,
                         vector<std::vector<cv::Point> >&contours,
                         vector<std::vector<cv::Point> >& contours2,
                         vector<int> idx);
};

#endif

This is my file segmentator.h.

In segmentator.c I have:

#include <stdio.h>
#include <stdlib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <sstream>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "segmentator.h"

void segmentator::search(/*parameters*/){/*CODE*/}
void segmentator::similar(/*parameters*/){/*CODE*/}
vector<Mat*> separate(/*parameters*/){/*CODE*/}

And then I am compiling like this

g++ -o segmentator.cpp `pkg-config --cflags opencv`

and it is not recognising the extensions of opencv library.

I moved the question with the new problem that appeared to: Not possible to compile. Headers files.Enclosed own objects definition

  • 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-04T07:48:49+00:00Added an answer on June 4, 2026 at 7:48 am

    Typically, you would first compile file.cpp into an object file:

    g++ -c file.cpp pkg-config –cflags opencv

    This produces file.o, which you then use to compile and link the main:

    g++ programMain.cpp file.o -o programMain pkg-config –cflags opencv pkg-config –libs opencv

    You should limit the includes in file.h to those you strictly need. Likewise for file.cpp.

    Edit: looking at your code, you need to do the following:

    • include the headers for cv::Mat and cv::Point in segmentator.h. I assume these would be opencv2/core/core.hpp although for me opencv/cv.h is fine on OpenCV 2.3.1.
    • include the header vector in segmantator.h
    • if your segmentator.c contains a main function, you need to link in the OpenCV libraries, so

      g++ segmentator.cpp -o segmentator pkg-config –cflags opencv pkg-config –libs opencv

    • if your segmentator.c does not have a main, i.e cannot be an executable, you can compile it into an object file, that you can use later to build applications:

      g++ -c segmentator.cpp pkg-config –cflags opencv

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

Sidebar

Related Questions

I have been searching everywhere but I could not find an answer. I need
I have been searching for answer for a while but i could not find
I have been searching for an answer to this question but could not find
I have been searching for a while but I could not find the answer,
I have been searching this for quite sometime but could not find an appropriate
I have been searching all over the internet for a solution, but could not
I have been searching but unable to find a proper list. Can someone please
I have been searching around using Google but I can't find an answer to
I have been searching for the answer and have not been able to find
I have been searching for about 12 hours now trying to find a way

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.