WX_DECLARE/DEFINE_OBJARRAY fails to link Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Blinkinhek
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue Aug 16, 2005 10:54 am

WX_DECLARE/DEFINE_OBJARRAY fails to link

Post by Blinkinhek » Wed Apr 30, 2008 3:30 pm

I get a link error
"Multiple definition of <objarrayname> ... first defined here ..."

whenever I use the Object Arrays:
eg
#include <wx/dynarray.h>
#include <wx/arrimpl.cpp>
class ctest
{
public:
int m_data;

void DoStuff(<params>) {stuff;}
};

Any thoughts on what I am doing wrong?

WX_DECLARE_OBJARRAY(ctest, ArrayOfTest);
WX_DEFINE_OBJARRAY(ArrayOfTest);

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Wed Apr 30, 2008 3:39 pm

header:

#include <wx/dynarray.h> // we must forward declare the array because it is used inside the class
class MyDirectory;
// now used as shown below
WX_DECLARE_OBJARRAY(MyDirectory, ArrayOfDirectories);



.cpp file:
#include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
WX_DEFINE_OBJARRAY(ArrayOfDirectories);


So You must move part of code from header file to .cpp and use something like:

#ifndef __MYHEADER__
#define __MYHEADER__

class...
..

#endif // __MYHEADER__

for .h file

Blinkinhek
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue Aug 16, 2005 10:54 am

Post by Blinkinhek » Wed Apr 30, 2008 4:09 pm

lester wrote:header:

#include <wx/dynarray.h> // we must forward declare the array because it is used inside the class
class MyDirectory;
// now used as shown below
WX_DECLARE_OBJARRAY(MyDirectory, ArrayOfDirectories);



.cpp file:
#include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
WX_DEFINE_OBJARRAY(ArrayOfDirectories);


So You must move part of code from header file to .cpp and use something like:

#ifndef __MYHEADER__
#define __MYHEADER__

class...
..

#endif // __MYHEADER__

for .h file
wow - that was quick !
Simply moving the WX_DEFINE_OBJARRAY to the .cpp file cured it.
It was originally in the header, and errored even the the header did have wrappers of #ifndef _MYHEADER_ ...#endif as you had suggested.
Anyway many thanks! :)

Post Reply