PDA

View Full Version : Mingw-32bit Vs MSVC2013-64bit Shared library issue



Vikram.Saralaya
1st December 2015, 12:32
Hello,

I have a shared library that works perfectly with mingw-32bit compiler. On MSVC2013-64bit compiler however I get a strange problem.

unresolved external symbol *__declspec(dllimport) .....

The problem is caused by a class in my shared library that is defined as:

class TEST_IMPORT_EXPORT className { .... }

TEST_IMPORT_EXPORT is defined as :

#ifdef BUILD_TEST_DLL
#define TEST_IMPORT_EXPORT Q_DECL_EXPORT
#else
#define TEST_IMPORT_EXPORT Q_DECL_IMPORT
#endif

I was wondering why the error says something about "dllImport" so I changed class definition to
class Q_DECL_EXPORT className { .... } and the MSVC2013-64bit works fine!

But I for sure think its not the right way to fix this issue. Can someone provide me more info as to what might be going on here?!

Thanks :)

Regards
Vikram

anda_skoa
4th December 2015, 16:21
Have you checked that BUILD_TEST_DLL is set when you are building the library?

Cheers,
_

Vikram.Saralaya
4th December 2015, 17:16
Aparently the first thing I did was that! It is set for sure..

ChrisW67
5th December 2015, 04:20
On Windows you have this coming from Qt:


# define Q_DECL_EXPORT __declspec(dllexport)
# define Q_DECL_IMPORT __declspec(dllimport)

as you can see, you ended up with the value of Q_DECL_IMPORT, which can only mean that your code:


#ifdef BUILD_TEST_DLL
#define TEST_IMPORT_EXPORT Q_DECL_EXPORT
#else
#define TEST_IMPORT_EXPORT Q_DECL_IMPORT
#endif

was preprocessed when BUILD_TEST_DLL was not defined.

If you add BUILD_TEST_DLL in your PRO file DEFINES, then you must rerun qmake to rewrite the Makefile or the value will not make it to the compiler.