C2491 definition of dllimport static data member not allowed

Jekteir

19-07-2007 00:57:24

Hi CaseyB,

Many thanks for all your help with licensing/compilation issues so far. Annoyingly we had to move from Code::Blocks to VC++ 2005 due to various problems with all the tools, and are now getting to experience VC++'s unique pecadillos with the repository we had just about got working with C::B and MinGW GCC! In particular right now there are a couple of errors with OgreAL's SoundManager during compilation using VC++ 2005:

>..\OgreAL\OgreALsrc\OgreALSoundManager.cpp(38) : error C2491: 'Ogre::Singleton<T>::ms_Singleton' : definition of dllimport static data member not allowed
> with
> [
> T=OgreAL::SoundManager
> ]


The line the above error actually points to is:


template<> OgreAL::SoundManager* Ogre::Singleton<OgreAL::SoundManager>::ms_Singleton = 0;


But, having read up a little on the error at http://msdn2.microsoft.com/en-us/library/62688esh(vs.71).aspx , I expect the problem is either in the class definition at:

class OgreAL_Export SoundManager : public Ogre::Singleton<SoundManager>, Ogre::FrameListener

or the define it references, which is actually at:


# ifdef OGRE_AL_EXPORT
# define OgreAL_Export __declspec(dllexport)
# else
--> # define OgreAL_Export __declspec(dllimport)
# endif


Note: my --> arrow refers to the line Visual Studio actually runs. I'm not trying to make a DLL, just use the source from within my project.

I thought about moving the OgreAL_Export out of the class definition and maybe onto the constructor, but I really had no idea what that would do (or why), so I left it alone...

In case it's relevant or useful, I include a few other errors/warnings from the compile (not the whole list by any stretch):


1>..\OgreAL\OgreALsrc\OgreALSoundManager.cpp(41) : warning C4273: 'FILE_TYPE' : inconsistent dll linkage
1> E:\Game\repos\client\trunk\OgreAL\OgreALinclude\OgreALSoundManager.h(186) : see previous definition of 'public: static std::basic_string<char,std::char_traits<char>,std::allocator<char> > const OgreAL::SoundManager::FILE_TYPE'
1>..\OgreAL\OgreALsrc\OgreALSoundManager.cpp(41) : error C2491: 'OgreAL::SoundManager::FILE_TYPE' : definition of dllimport static data member not allowed
1>..\OgreAL\OgreALsrc\OgreALSoundManager.cpp(42) : warning C4273: 'OGG' : inconsistent dll linkage


[ edit ] -- cut out lots of unnecessary errors -- these are enough to express the issue [ /edit]

Could you help me out please?

Many thanks,

Jek

Jekteir

19-07-2007 16:13:18

I've tried putting #include "OgreALPrereqs.h" at the top of OgreAL.h , which is what I include in my game cpp file, to make sure that the dllimports are correctly defined before any other ogreal stuff happens -- no dice.

Jekteir

19-07-2007 16:51:06

And I can confirm we have the latest Eihort-compatible code from the repository.

Jekteir

19-07-2007 17:21:41

Just tried changing the /MDd to /MTd setting in C++/Code Generation as suggested in this thread:

http://www.ogre3d.org/phpBB2/viewtopic.php?t=26379

No luck. Have set it back now.

I've been reading up at:

http://msdn2.microsoft.com/en-us/library/35bhkfb6(vs.80).aspx
http://support.microsoft.com/kb/815647
http://www.gamedev.net/community/forums ... _id=301008
http://www.gamedev.net/community/forums ... hichpage=1

but no go so far.

This is the total set of OgreAL errors:


1>OgreALWavSound.cpp
1>e:\game\repos\client\trunk\ogreal\ogrealsrc\ogrealwavsound.cpp(40) : warning C4273: 'OgreAL::WavSound::WavSound' : inconsistent dll linkage
1> e:\game\repos\client\trunk\ogreal\ogrealinclude\ogrealwavsound.h(69) : see previous definition of '{ctor}'
1>e:\game\repos\client\trunk\ogreal\ogrealsrc\ogrealwavsound.cpp(63) : warning C4273: 'OgreAL::WavSound::~WavSound' : inconsistent dll linkage
1> e:\game\repos\client\trunk\ogreal\ogrealinclude\ogrealwavsound.h(73) : see previous definition of '{dtor}'
1>e:\game\repos\client\trunk\ogreal\ogrealsrc\ogrealwavsound.cpp(66) : warning C4273: 'OgreAL::WavSound::errorToString' : inconsistent dll linkage
1> e:\game\repos\client\trunk\ogreal\ogrealinclude\ogrealwavsound.h(77) : see previous definition of 'errorToString'
1>Generating Code...
1>Compiling...
1>OgreALSoundStream.cpp
1>e:\game\repos\client\trunk\ogreal\ogrealsrc\ogrealsoundstream.cpp(41) : warning C4273: 'OgreAL::SoundStream::SoundStream' : inconsistent dll linkage


[ edit ] -- cut out lots of unnecessary errors -- these are enough to express the issue [ /edit]

I've confirmed that my project settings are the same as those of the Ogre project. Your demos build, but I've noticed none use ogrealwavsound or ogrealsoundstream, for example.

Jek

Jekteir

19-07-2007 17:50:20

I got OgreAL to compile by replacing all the lines that use OGREAL_EXPORT, e.g.:

//class OgreAL_Export SoundStream : public Sound
class SoundStream : public Sound

Will post back if it links ok and runs sounds etc.

Jekteir

19-07-2007 18:12:28

Well, it compiles and links and runs and plays sounds, so everything seems OK. Do you know whether my changes are likely to create any ill effects under particular conditions?

Cheers,

Jek

CaseyB

19-07-2007 18:23:08

Yeah, when you are creating a DLL you need to define define OgreAL_Export as __declspec(dllexport), if you are using the DLL you need to define it as __declspec(dllimport) and if you are just using the source inside your application you would need to define it as a NULL so it would look like this# define OgreAL_ExportKeep in mind the LGPL if you are static linking though.

Jekteir

19-07-2007 19:00:29

OK, well, I thought that OgreAL was importing Ogre classes for inheritance, or maybe OpenAL functions? But if all that stuff was in terms of exporting or importing OgreAL, yeah, I just have the OgreAL headers and source in my files. So I guess that defining it as null is the same as removing OgreAL_Export from the classes. That's static usage I guess? I'll have to brush up on my LGPL/check your preambles to see what that means.

sapan280

27-03-2008 17:03:39

initially i was also getting the same problem... but i solved it

follow the steps...

1. just delete extra elements from "Additional Include Directories" .
2. just delete extra elements from "Additional Library Directories" .

just the additional file directories from the "OgreAL" project property...
for both debug and release

:D good luck

Jekteir

27-03-2008 18:58:48

Hi sapan280,

Not sure what your issue was, but in my case the correct solution was CaseyB's. The #ifdef OGRE_AL_EXPORT (etc) lines from OgreAL's OgreALPrereqs.h file select whether or not to: a) import OgreAL's object code (as opposed to the headers) from a DLL; or b) export the code upon compilation to a DLL; or c) compile the code statically, neither exporting to nor importing from DLL's but rather embedding the compiled code directly into the executable for your project.

During my project so far I have been static linking (that's what this embedding is) and hence needed the macro OgreAL_Export defined as nothing, so that the code compiled as if it were just another part of my project. I will go back to dynamic linking if/when I need to comply with the licensing of the various project components at release time.

Jek

Rambus

22-05-2008 01:04:07

I know this is a bump but..

initially i was also getting the same problem... but i solved it

follow the steps...

1. just delete extra elements from "Additional Include Directories" .
2. just delete extra elements from "Additional Library Directories" .

just the additional file directories from the "OgreAL" project property...
for both debug and release

:D good luck


I had the same problem and the above solution fixed it instantly. Everyone might want to try that one first :)

(Remove the 2nd Ogre reference, that is if you are using SRC delete the HOME references- I also removed the BOOST include reference which might have been the problem as well)