derived class produces dll linkage error?
pahsieh at usgs.gov
pahsieh at usgs.gov
Tue May 16 17:29:42 EDT 2000
Larry:
The proper setup depends on what you want to do. There are
three possibilities.
1. You want to compile your derived class to become a part of
vtkdll.dll. For this case, your setup is correct. However, I assume
this is not what you are trying to do.
2. You want to compile your derived class along with the rest
of your code into an executable. In this case, just get rid of
VTK_EXPORT in the class definition. In other words,
#include "vtkImageReader.h"
class vtkI2IReader : public vtkImageReader
{
...
}; // <-- Dont forget the semicolon
3. You want to compile you derived class into a dll that is separate
from vtkdll.dll. Call it vtki2i.dll. In this case,
you should replace VTK_EXPORT with something else, for example
#include "vtkImageReader.h"
#ifdef I2IDLL
#define I2I_EXPORT __declspec(dllexport)
#else
#define I2I_EXPORT __declspec(dllimport)
#endif
class I2I_EXPORT vtkI2IReader : public vtkImageReader
{
...
};
When you build vtki2i.dll, you would define I2IDLL so that your
derived class is __declspec(dllexport). However, you would not
define VTKDLL (see the vtkWin32Header.h) so that the vtk classes
are __declspec(dllimport).
When you build your executable, you would define neither I2IDLL
nor VTKDLL.
You current setup does not work because of the following reason.
When you build in Win32, the following lines in vtkWin32Header.h
will be included:
#ifdef VTKDLL
#define VTK_EXPORT __declspec( dllexport )
#else
#define VTK_EXPORT __declspec( dllimport )
#endif
Assuming you haven't defined VTKDLL, your derived class is actually
class __declspec(dllimport) vtkI2IReader : public vtkImageReader
{
...
};
This tells the compiler that this class is imported from a dll
(Just like all the other vtk classes). Therefore, the compiler
would only expect the header (.h) file in the project, but not
the implementation (.cpp) file. When the compiler encounters
the body of the member functions in the implementation file,
the warnings are issued.
Hope this makes sense.
Paul
"Lawrence M. Lifshitz"
<Lawrence.Lifshitz at umas To: vtkusers at public.kitware.com
smed.edu> cc:
Sent by: Subject: derived class produces dll linkage
owner-vtkusers at public.k error?
itware.com
05/16/00 01:15 PM
hi. I am trying to extend the vtkImageReader class to read
my own image format (i2i). I seem to have a problem linking
with vtkdll.lib. I am working on Win98/VC++6, using the precompiled
libraries. I have had no problem linking with this library to
run several of the demo programs, which don't try to derive a new
class. So I am thinking that the difference has to do with the
fact that I am trying to derive a class. The message I get for
each method is (for the New method, similar messages for other methods):
vtki2ireader.cxx(54) : warning C4273: 'New' : inconsistent dll linkage.
dllexport assumed.
The relevant snippet of code is:
.h file:
#include "vtkImageReader.h"
class VTK_EXPORT vtkI2IReader : public vtkImageReader
{
public:
static vtkI2IReader *New();
...
}
.cxx file:
vtkI2IReader* vtkI2IReader::New()
does it not realize I am doing "implicit" linking using the vtkdll.lib
to import from
vtk.dll, and therefore it mangles (decorates?) methods incorrectly?
when it says
"dllexport" assumed, does that mean it thinks I'm trying to create a
library?
should I just ignore the warning? does VC++ require anything different
for generic derived
classes (all the docs I've seen talk about MFC based derived classes)?
Any pointers would be helpful!
Larry
--
Lawrence M. Lifshitz, Ph.D.
Biomedical Imaging Group - University of Massachusetts Medical School
Phone: (508) 856-3392 email: Lawrence.Lifshitz at umassmed.edu
FAX: (508) 856-1840 web:
http://invitro.umassmed.edu/~lml
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------
More information about the vtkusers
mailing list