Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Use x64 DLL
QtWS25 Last Chance

[solved]Use x64 DLL

Scheduled Pinned Locked Moved General and Desktop
x64 dll64bit
13 Posts 5 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    catalin1122
    wrote on last edited by catalin1122
    #1

    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;
    }
    

    SocketTest.pro

    
    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you trying to link your 64bit DLL with a 32bit Qt build ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Are you trying to link your 64bit DLL with a 32bit Qt build ?

        C Offline
        C Offline
        catalin1122
        wrote on last edited by
        #3

        @SGaist
        Yes.

        1 Reply Last reply
        0
        • FranckynosF Offline
          FranckynosF Offline
          Franckynos
          wrote on last edited by
          #4

          @catalin1122 said:

          TestDllToQT.lib

          It's impossible, you need to have your TestDllToQT.lib compile in the same architecture.

          C 1 Reply Last reply
          0
          • FranckynosF Franckynos

            @catalin1122 said:

            TestDllToQT.lib

            It's impossible, you need to have your TestDllToQT.lib compile in the same architecture.

            C Offline
            C Offline
            catalin1122
            wrote on last edited by
            #5

            @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.

            FranckynosF 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Use a 64bit Qt build

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • C catalin1122

                @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.

                FranckynosF Offline
                FranckynosF Offline
                Franckynos
                wrote on last edited by Franckynos
                #7

                @catalin1122
                http://tver-soft.org/qt64

                Here 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/)

                1 Reply Last reply
                1
                • C Offline
                  C Offline
                  catalin1122
                  wrote on last edited by catalin1122
                  #8

                  I've downloaded msvc2012 from here and Qt Creator 3.5.0 x64 from here. I have installed them and changed the kit and compiler but i still get those errors.

                  Any ideas?

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    belab
                    wrote on last edited by
                    #9

                    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

                    C 1 Reply Last reply
                    1
                    • B belab

                      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

                      C Offline
                      C Offline
                      catalin1122
                      wrote on last edited by
                      #10

                      @belab
                      Hi,
                      I did that, except the part extern "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.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        You just defined the export not import. Qt's Creating Shared Library documentation chapter explain how to do it properly

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • hskoglundH Offline
                          hskoglundH Offline
                          hskoglund
                          wrote on last edited by
                          #12

                          Hi, SGaist is correct, just want to add, to see an example how to use Q_DECL_EXPORT and Q_DECL_IMPORT, you can create a test project in Qt Creator: New File or Project, Library, C++ Library. Look in the xxx_global.h file created...

                          1 Reply Last reply
                          1
                          • C Offline
                            C Offline
                            catalin1122
                            wrote on last edited by catalin1122
                            #13

                            @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! :-)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved