• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

linker error with externed value

I am getting a 2019 linker error followed by a 1120 when I try to access matrix lut_max in a thread. I externed the value in the thread (thus leading to the error) becuase I was getting an unknown identifier error without it. The reason I do not create the table in the thread is becuase I only need to create it once, and the thread would create it multiple times. I wrote a function that writes the table once from my GUI. I instatiate the class with

FxLUT FxLUTInst;

Then I call the function

FxLUTINst.WriteTable();

All the class and function do is write the table, no erros there.

My extern statement is:

extern CvMat* lut_mat;

I am sure that this is something simple or simly done wrong. Please help.

Thanks

WLE

error in full:

 C:\...\OpenCVThread1.obj [Error LNK2019] unresolved external symbol "struct CvMat * lut_mat" (?lut_mat@@3PAUCvMat@@A) referenced in function "public: virtual void * __thiscall OpenCVThread::Entry(void)" (?Entry@OpenCVThread@@UAEPAXXZ)
0
Wanderinglazyeye
Asked:
Wanderinglazyeye
  • 3
  • 2
  • 2
  • +1
5 Solutions
 
efnCommented:
Your declaration of lut_mat is saying it is defined somewhere else.  That means somewhere you need a similar declaration at file scope without the "extern" keyword.  Do you have one?
0
 
Infinity08Commented:
Does the FxLUTInst contain the CvMat ? And is it at file scope ? Something like this :

        class FxLUT {
            private :
                CvMat *lut_mat;
            public :
                CvMat *getMat() { return lut_mat; }
        };

        static FxLUT FxLUTInst;

If so, you need to put this in your thread source file :

        extern FxLUT FxLUTInst;

and then you can get the matrix in your thread like this :

        CvMat *theMatrix = FxLUTInst.getMat();
        // use the matrix ...
0
 
rstaveleyCommented:
> I externed the value in the thread (thus leading to the error) becuase I was getting an unknown identifier error without it.

The "extern" keyword isn't what you are after. I suspect that you are looking for "static".
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WanderinglazyeyeAuthor Commented:
Here is what I have now, still with some errors:

.cpp
----------------------
class FxLUT
{

private :
   CvMat *lut_mat;


public:
    FxLUT();
    ~FxLUT();

    bool WriteLUT();
    CvMat *getMat() { return lut_mat; }

};

.h
---------------

FxLUT::FxLUT()
{
}

FxLUT::~FxLUT()
{
}

//function to create lookup table

bool FxLUT::WriteLUT()
{

uchar lut[256];
CvMat* lut_mat;
lut_mat = cvCreateMatHeader( 1, 256, CV_8UC1 );
cvSetData( lut_mat, lut, 0 );   //set the matrix data to NULL
for(int i = 0; i < 256; i++ )
{
if ((i>105)&&(i<117))
{
lut[i] = i;
}
else
{
    //nada
}
}

    return true;
}


call from the GUI:
---------------------------

I am getting an error with CVMat *LutMat and the return lut_mat statement. To clarify, CVMat is an open cv function. What is the error in my coding?


0
 
rstaveleyCommented:
Do you want a local...

    CvMat* lut_mat;

...in WriteLUT? Try commenting it out.
0
 
Infinity08Commented:
1) First of all, you have the .cpp and .h files mixed up - it should be the other way around. Plus you should include the .h file at the top of the .cpp file.

Then you have to have a globale instance of the FxLUT class somewhere, which you can then access using the extern statement.


2) In your FxLUT::WriteLUT(), do not create a local variable lut_mat - instead just use the lut_mat from the class. Or in short, remove this line :

        CvMat* lut_mat;


3)

>> I am getting an error with CVMat *LutMat and the return lut_mat statement.

What is the error you get. And can you also show the code where you get the error ?


4)

>> To clarify, CVMat is an open cv function.

A function ? Or a class ?
0
 
WanderinglazyeyeAuthor Commented:
Ok sorry about the .cpp & .h mix up.

Here is again with errors:

.h
---------------------------

class FxLUT
{

private :
   CvMat *lut_mat;   //LINE 29


public:
    FxLUT();
    ~FxLUT();

    bool WriteLUT();
    CvMat *getMat() { return lut_mat; } //LINE 37

};


.cpp
--------------------------
using namespace std;

extern CvMat *LutMat

FxLUT::FxLUT()
{
}

FxLUT::~FxLUT()
{
}

//function to create lookup table

bool FxLUT::WriteLUT()
{

uchar lut[256];
//CvMat* lut_mat;
lut_mat = cvCreateMatHeader( 1, 256, CV_8UC1 );
cvSetData( lut_mat, lut, 0 );   //set the matrix data to NULL
for(int i = 0; i < 256; i++ )
{
if ((i>105)&&(i<117))
{
lut[i] = i;
}
else
{
    //nada
}
}

    return true;
}

ABC.cpp   //main gui, write - call just once
-----------
...
static FxLUT FxLUTInst;

...

FxLUTInst.WriteLUT();

Thread.cpp
-------------------

access LUT table here



errors line 37:
37 c:\...\LUT.h [Error C2143] syntax error : missing ';' before '*'
37 c:\...\LUT.h [Error C4430] missing type specifier - int assumed. Note: C++ does not support default-int
37 c:\...\\LUT.h [Error C4430] missing type specifier - int assumed. Note: C++ does not support default-int
37 c:\...\LUT.h [Warning C4183] 'getMat': missing return type; assumed to be a member function returning 'int'
37 c:\...\LUT.h [Error C2065] 'lut_mat' : undeclared identifier

line 29:
29 c:\...\\LUT.h [Error C2143] syntax error : missing ';' before '*'
29 c:\...\LUT.h [Error C4430] missing type specifier - int assumed. Note: C++ does not support default-int
29 c:\...\\LUT.h [Error C4430] missing type specifier - int assumed. Note: C++ does not support default-int  
0
 
efnCommented:
I think the compiler is trying to tell you that when it tries to compile the .h file, it doesn't know what a CvMat is.  If you have a header file that declares CvMat, you should #include that in the .h file.  If you don't, you can either make one and #include it, or just add the declaration to the existing .h file.
0
 
Infinity08Commented:
So, does it work now ? What code do you have ?

It should be something like this :


---- fxlut.h ----

#include "the_include_for_cvmat.h"

class FxLUT
{

private :
   CvMat *lut_mat;   //LINE 29


public:
    FxLUT();
    ~FxLUT();

    bool WriteLUT();
    CvMat *getMat() { return lut_mat; } //LINE 37

};

---- ----

---- fxlut.cpp ----

#include "fxlut.h"

FxLUT::FxLUT()
{
}

FxLUT::~FxLUT()
{
}

//function to create lookup table

bool FxLUT::WriteLUT()
{

uchar lut[256];
//CvMat* lut_mat;
lut_mat = cvCreateMatHeader( 1, 256, CV_8UC1 );
cvSetData( lut_mat, lut, 0 );   //set the matrix data to NULL
for(int i = 0; i < 256; i++ )
{
if ((i>105)&&(i<117))
{
lut[i] = i;
}
else
{
    //nada
}
}

    return true;
}

---- ----

---- ABC.cpp ----   //main gui, write - call just once

#include "fxlut.h"
...
static FxLUT FxLUTInst;

...

FxLUTInst.WriteLUT();

---- ----

---- Thread.cpp ----

#include "fxlut.h"

extern FxLUT FxLUTInst;

void theThreadFunction() {
        CvMat *theMatrix = FxLUTInst.getMat();
        // use the matrix ...
}

---- ----
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now