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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:24:45+00:00 2026-06-04T22:24:45+00:00

Here I am with a similar question as the last time, and for which

  • 0

Here I am with a similar question as the last time, and for which I could not find any answer.

Note that I consider important: Normally I compile my programs in opencv with the next command:

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

This line will create an executable whose name will be def and that I will be able to use.

I am working in a project, and as it was getting bigger, I had to define some objects, just to make everything easier and possible to handle. I create one object from the files: homogra.cpp and homogra.h the comand I used for it was:

g++ -c  homogra.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`

Then, I wrote in my program.cpp the line #include “homogra.h”

And I compile like:

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

Until now everything is working fine.

Then I create a second object(with the same compilation line as for homogra, but this time with segmentator.cpp and segmentator.h), i wrote the line #include “segmentator.h”,(in program.cpp) and I compile like:

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

Now it is not working, and it is not recognising segmentator. I checked already if segmentator was working and everything works fine if homogra is the only include in the program.cpp.

I notice something strange. If I change the lines and I write before,in the #include lines, #include “segmentator.h” and then #include “homogra.h”, then the compiler, with the same line for compiling :

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

is only recognising this time segmentator and not homogra. It is maybe a little difficult to understand, I tried to explained it as better as possible.

Any help!?

Many thanks in advance.

Here is homogra.h:

using namespace cv;
using namespace std;

#ifndef _NAMES_H  
#define _NAMES_H   
class homogra {
public:

    Mat matCalculation( Mat img, Mat img2);
    void printMatrix(Mat matrix);

};
#endif

In homogra.cpp I have all the tipical includes and homogra.h:

#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 "homogra.h"

And then the functions explained.

Object 2 is segmentator.h

 using namespace cv;
 using namespace std;

#ifndef _NAMES_H  
#define _NAMES_H   
 class segmentator {
public:

    void search(Mat img,vector<std::vector<cv::Point> >& contours);

     void similar(vector<std::vector<cv::Point> >& contours,vector<std::vector<cv::Point> >& contours2,vector<int>& idx);

    vector<Mat> separate(Mat img,Mat img2,vector<std::vector<cv::Point> >&   contours,vector<std::vector<cv::Point> >& contours2,vector<int> idx);
};

#endif

And in segmentator.cpp I have again all the same includes, except homogra.h and instead of this one I have segmentator.h.

Program.cpp is image_reg.cpp:

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

#include "homogra.h"
#include "segmentator.h" 
 using namespace cv;
 using namespace std;

int main(int argc, char ** argv )
{ //Here is the code where I try to invoque two instances of homogra and segmentator.
}

If I let homogra.h as the first to be read in the includes list of image_reg.cpp then only homogra.h is recognised, if I let at the first position segmentator, then only segmentator.h instances would be created and homogra. h would not be recognised.

Thanks

  • 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-04T22:24:47+00:00Added an answer on June 4, 2026 at 10:24 pm

    Your include header guards are wrong. They should be unique, using the name of the source file, rather than just _NAMES_H.

    So in homogra.h you should have this:

    #ifndef HOMOGRA_H  
    #define HOMOGRA_H   
    ...
    #endif
    

    …and in segmentator.h, you should have this

    #ifndef SEGMENTATOR_H  
    #define SEGMENTATOR_H   
    ...
    #endif
    

    Also, it’s really bad practice to have a using namespace xxx; in a header file. You make it very difficult for your headers to coexist with others.

    As Jonathan Wakely points out, beginning symbols with underscores is not a great idea, either.

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

Sidebar

Related Questions

I've looked around here for similar question but couldn't find any that solved my
I ask a similar question here and Darin Dimitrov answer that we can't use
Notice that I am asking for little-o here (see similar question here ) -
This question is philosophically similar to a question that's come up time and time
Its similar question that I asked yesterday here with a slight modification. Here are
There is a similar question here on SO, but I have a fairly small
I asked a very similar question here but since it is such a fundamental
I've posted similar question here , but it was closed because I didn't explained
I've found a similar question here , but I'm looking for more general solutions.
I already looked at a similar question here : null pointer exception-parsing json with

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.