[solved]Use x64 DLL
-
Hello guys,
I want to use in Qt a DLL build in VS2012 on x64. DLL's name is TestDllToQT and it contains a class named Sum.
Sum.h
#pragma once #define GAME_API __declspec (dllexport) class GAME_API Sum { private: int a; int b; public: Sum(void); ~Sum(void); void setA( int val) { a = val; } void setB( int val) { b = val; } int SumAandB(); };
Sum.cpp
#include "Sum.h" Sum :: Sum(void) { } Sum :: ~Sum(void) { } int Sum :: SumAandB() { return a+b; }
QT += core QT -= gui TARGET = SocketTest CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp \ win32: LIBS += -L$$PWD/Dependencies/ -lTestDllToQT INCLUDEPATH += $$PWD/Dependencies DEPENDPATH += $$PWD/Dependencies win32:!win32-g++: PRE_TARGETDEPS += $$PWD/Dependencies/TestDllToQT.lib else:win32-g++: PRE_TARGETDEPS += $$PWD/Dependencies/libTestDllToQT.a
Main.cpp
#include <QCoreApplication> #include "myserver.h" #include <QLibrary> #include <Sum.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Sum adn; adn.setA(5); adn.setB(7); qDebug()<<adn.SumAandB(); return a.exec(); }
And these are the errors that i get:
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Sum::Sum(void)" (??0Sum@@QAE@XZ) referenced in function _main main.obj : error LNK2019: unresolved external symbol "public: __thiscall Sum::~Sum(void)" (??1Sum@@QAE@XZ) referenced in function _main main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Sum::SumAandB(void)" (?SumAandB@Sum@@QAEHXZ) referenced in function _main release\SocketTest.exe : fatal error LNK1120: 3 unresolved externals
If i build the DLl on x32 it builds in Qt and everything works fine. The problem appears when i build it on x64.
What can I do to make it work?
Thank you!
-
Hi,
Are you trying to link your 64bit DLL with a 32bit Qt build ?
-
@catalin1122 said:
TestDllToQT.lib
It's impossible, you need to have your TestDllToQT.lib compile in the same architecture.
-
@Franckynos
Is there a way to make my Qt project x64 and compatible with the dll? I could compile the dll in x32 but I would prefer not to. -
Use a 64bit Qt build
-
@catalin1122
http://tver-soft.org/qt64Here there was pre-build qt x 64 but the server not respond. :(
You need to find (or compile) qt in 64 bits(http://sourceforge.net/projects/qt64ng/files/qt/x86-64/5.4.2/mingw-5.1/seh/)
-
Hi catalin1122,
when linking against your dll you have to import the symbols, when creating the dll the symbols have to be exported this is usually done with some macros like in the following link - http://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport -
@belab
Hi,
I did that, except the partextern "C"
.When I import the DLL how do I do it in Qt? Now I do it statically (in *.pro) and I get those errors. The thing is that when I compile the DLL on x32 it works the way I do it. But not in x64.
-
You just defined the export not import. Qt's Creating Shared Library documentation chapter explain how to do it properly
-
@SGaist @hskoglund @belab @Franckynos
Thank you for helping me!You were right, I did not import the symbols.
I added this :
#ifdef GAME_EXPORTS # define GAME_API __declspec(dllexport) #else # define GAME_API __declspec(dllimport) #endif
to my DLL code and now everything works.
Have a nice day, you rock! :-)