Link to home
Start Free TrialLog in
Avatar of Wanderinglazyeye
Wanderinglazyeye

asked on

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)
SOLUTION
Avatar of efn
efn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wanderinglazyeye
Wanderinglazyeye

ASKER

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?


Do you want a local...

    CvMat* lut_mat;

...in WriteLUT? Try commenting it out.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ...
}

---- ----