giro82 (23) Mar 22, 2010 at 6:40am UTC
Hi!
I have following problem:
Namely,when I use keyword "extern " to get the value of standard variable (e.g.float,int,..) or array located in one file and use it in another file, everything works fine.
Problems appear when I recall to matrix variable (I use matrix.h library from http://www.techsoftpl.com/matrix/matlite.htm )then I got this message:
[Linker Warning] Public symbol '_slupek' defined in both module C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\05.11.2009\SLUPKI.OBJ and C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\05.11.2009\KATY.OBJ
Below are listings maybe someone will find mistake.
slupki.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#ifndef SLUPKIH
#define SLUPKIH
#include "matrix.h"
#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
#ifndef _NO_TEMPLATE
typedef matrix<double > Matrix;
#else
typedef matrix Matrix;
#endif
/////////////////////////////////
Matrix slupki();
#endif //SLUPKIH
slupki.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "matrix.h"
#include "slupki.h"
//////////////////////////////
Matrix slupek(6,2); //matrix variable declaration
double x_1[6];
double x_2[6];
Matrix slupki()
{
for (int i=0;i<6;i++)
{
slupek(i,0)=3;
slupek(i,1)=3;
x_1[i]=slupek(i,0);
x_2[i]=slupek(i,1);
}
return (slupek);
}
katy.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef KATYH
#define KATYH
#include "matrix.h"
#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
#ifndef _NO_TEMPLATE
typedef matrix<double > Matrix;
#else
typedef matrix Matrix;
#endif
//////////////////////////////
Matrix katy();
#endif //KATYH
katy.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "slupki.h"
#include "matrix.h"
/////////////////////////////////////
double y_1[6];
double y_2[6];
//extern double x_1[6];
//extern double x_2[6];
Matrix kat(6,2);
extern Matrix slupek(6,2);
Matrix katy()
{
for (int i=0;i<6;i++)
{
kat(i,0)=slupek(i,0)+1; // recall to 1.column of matrix slupek(6,2)
kat(i,1)=slupek(i,1)+1; // recall to 2.column of matrix slupek(6,2)
y_1[i]=kat(i,0);
y_2[i]=kat(i,1);
}
return (kat);
}
ftest.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ftest.h"
#include "katy.h"
#include "slupki.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
slupki();
katy();
extern double x_1[6];
extern double x_2[6];
extern double y_1[6];
extern double y_2[6];
for (int i=0;i<6;i++)
{
StringGrid1->Cells[0][i]=AnsiString(x_1[i]);
StringGrid1->Cells[1][i]=AnsiString(x_2[i]);
StringGrid2->Cells[0][i]=AnsiString(y_1[i]);
StringGrid2->Cells[1][i]=AnsiString(y_2[i]);
}
}
//---------------------------------------------------------------------------
When I put extern double x_1[6] and extern double x_2[6] above katy() function in katy.cpp additionally I slash out extern Matrix slupek(6,2) and replace respectively slupek(i,0) and slupek(i,1) with x_1[i] and x_2[i] my program works fine.
Maybe the problem is in matrix.h library.
I work with Builder 6 Enterprise.
Any ifnormation concerning matrix.h can be found under http://www.techsoftpl.com/matrix/matlite.htm
I will be appreciate for any remarks.
guestgulkan (1306) Mar 22, 2010 at 6:40am UTC
katy.cpp
1 2
#include "slupki.h" // ?????? Is this right or should it be #include "katy.h"
#include "matrix.h"
jsmith (3807) Mar 22, 2010 at 6:40am UTC
This can't be right, but I don't know why it compiles without error:
extern Matrix slupek(6,2);
It should be
giro82 (23) Mar 22, 2010 at 6:40am UTC
It should be #include "katy.h" but the outcome is the same as for #include "slupki.h"
guestgulkan (1306) Mar 22, 2010 at 6:40am UTC
But then ftest.cpp: includes both these files like this:
ftest.cpp:
1 2
#include "katy.h"
#include "slupki.h"
so you are no further forward.
You need to re-arrange your global variables
giro82 (23) Mar 22, 2010 at 6:40am UTC
jsmith ,
it doesn't work with:
extern matrix slupek;
I got messages like this:
[C++ Error] katy.cpp(9): E2102 Cannot use template 'matrix<T>' without specifying specialization parameters
[C++ Error] katy.cpp(9): E2040 Declaration terminated incorrectly
[C++ Error] katy.cpp(15): E2268 Call to undefined function 'slupek'
giro82 (23) Mar 22, 2010 at 6:40am UTC
guestgulkan ,
how to rearrange this?
guestgulkan (1306) Mar 22, 2010 at 6:40am UTC
Hang on, I got a bit confused there didn't I? :-)
I got confused with slupki (which is a function) and slupek (which is a variable).
So ignore what I said in the previous posts.
//---------------------------------------------------------------
So the problem is with the declaration of the slupek variable.
This Matrix slupek(6,2); and this extern Matrix slupek(6,2); are both the same
in that they are both definitions
One should be Matrix slupek(6,2); and the other should be extern Matrix slupek; .
So pretty much as JSmith said.
Last edited on Mar 22, 2010 at 6:40am UTC
giro82 (23) Mar 22, 2010 at 6:40am UTC
Now it works, ;-)
Thanks a lot guys!
This topic is archived - New replies not allowed.