This forum has been archived. All content is frozen. Please use KDE Discuss instead.

__declspec(dllexport) - Library problem on Windows

Tags: None
(comma "," separated)
stephma
Registered Member
Posts
1
Karma
0
Hi

I'm having troubles for exporting a class that derives from an Eigen::Matrix under windows. More specifically, following code:
Code: Select all
#include "Eigen/Core"
class __declspec(dllexport) myVector : public Eigen::Matrix<double, 3, 1> {};


Produces a warning C4251: warning C4251: 'Eigen::Matrix<_Scalar,_Rows,_Cols>::m_storage' : class 'Eigen::ei_matrix_storage<T,Size,_Rows,_Cols,_Options>' needs to have dll-interface to be used by clients of class 'Eigen::Matrix<_Scalar,_Rows,_Cols>'

and 5 errors C2487 : error C2487:
'Eigen::MatrixBase<Derived>::setConstant' : member of dll interface class may not be declared with dll interface
'Eigen::MatrixBase<Derived>::setZero' : member of dll interface class may not be declared with dll interface
'Eigen::MatrixBase<Derived>::setOnes' : member of dll interface class may not be declared with dll interface
'Eigen::MatrixBase<Derived>::setRandom' : member of dll interface class may not be declared with dll interface
'Eigen::MatrixBase<Derived>::setIdentity' : member of dll interface class may not be declared with dll interface

The warning can be removed using explicit template instantiation, ie writing following lines before the declaration of myVector:
Code: Select all
template struct __declspec(dllexport) Eigen::ei_matrix_array<double, 3, Eigen::ColMajor|Eigen::AutoAlign>;
template class __declspec(dllexport) Eigen::ei_matrix_storage<double, 3, 3, 1, Eigen::ColMajor|Eigen::AutoAlign>;


But I think that the error C2487 is due to a flaw in Visual Studio's compiler when instantiating Derived in MatrixBase.h. Here (MatrixBase.h, line 443) 'Derived' is replaced by '__declspec(dllexport) Eigen::Matrix<double, 3, 1>' so that the declaration of the method setConstant() (and others) looks like a member declared with dll interface.

What is the right way for exporting a class that inherits from a instantiation of an EigenMatrix?

Thanks for your help

Steph
petzchen
Registered Member
Posts
1
Karma
0
I have a similar problem. I want to create a static library with VS on Windows.
What should I consider for exporting the right stuff.

Thanks for your help.

Best wishes
Stephan
User avatar
Darkstar
Registered Member
Posts
11
Karma
0
Hi,

was there ever any solution (or at least a workaround) to this problem?
Current KDE trunk has the exact same problem (in kdebase\runtime\nepomuk\services\backupsync\lib\simpleresource.h)

An exported class that derives from QMultiHash<Foo, Bar> and which throws the same error in MSVC.

Edit: kdepim also suffers from this in kdepim\mailcommon\filteraction.h

-Darkstar


This is not a signature...
User avatar
lpapp
Registered Member
Posts
9
Karma
0
OS
Same problem again with nepomuk-core.
User avatar
Darkstar
Registered Member
Posts
11
Karma
0
See here for a possible solution

-Darkstar


This is not a signature...
User avatar
lpapp
Registered Member
Posts
9
Karma
0
OS
I do not see this error message mentioned there. As if different ones had been discussed in there, but I may be wrong as I am a no expert about msvc. :-)
User avatar
Darkstar
Registered Member
Posts
11
Karma
0
The problem is with template instantiations. DLL files cannot export non-instantiated templates. These must be self-contained in the .h file.

this is, generally, a quite difficult problem because depending on the source code it requires quite a lot of changes


This is not a signature...
User avatar
lpapp
Registered Member
Posts
9
Karma
0
OS
I presume the problem is also that nepomuk-core should keep the binary compatibility and this might make the situation very difficult.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]