Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED]Cannot resolve the symbols from a custom dll

[SOLVED]Cannot resolve the symbols from a custom dll

Scheduled Pinned Locked Moved Installation and Deployment
9 Posts 6 Posters 10.9k 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.
  • M Offline
    M Offline
    magpielover
    wrote on last edited by
    #1

    Hello,
    I am very close to tear all my hairs out. I have been trying to resolve the functions from my custom dll but so far, no luck.

    Here is the template I use:

    @QLibrary library("E:/QT_works/myDll.dll");

    if(library.load())
    qDebug()<<"Loading done";

    typedef void (*MyPrototype)();
    MyPrototype myFunction = (MyPrototype) myLib.resolve("myFunction");
    if (myFunction)
    myFunction();@

    Loading is successful. However, symbols cannot be resolved.
    I used debugger and after the myLib.resolve step, the following error appears on the window where name and values are shown;

    bq. errorString "Cannot resolve symbol "myFunction" in E:/QT_works/myDll.dll: The specified procedure could not be found." QString

    I also used
    @HINSTANCE hDLLFeX;
    hDLLFeX=LoadLibrary(L"myDll.dll");
    if(hDLLFeX)
    qDebug()<<"LOAD SUCCESSFUL";

             MyPrototype myFunction = (MyPrototype)  GetProcAddress(hDLLFeX, "myFunction");@
    

    Both return a null pointer.
    It's obvious that I cannot find the function declared in the library source file, but I guess I used correct syntax when declaring my function. What I used was

    @extern "C" {
    ...
    void myFunction(int,int)

    }@

    It's good to mention that the same dll was used by someone else earlier in VS 6.0.

    I also downloaded DependencyWalker and check the names of the functions inside myDll.dll. I noticed something which seemed to be interesting. The name of the function which dependencywalker shows is _Z8myFunctionPd, _Z8 in front and Pd at the end of the function. I guess it shouldn't be a problem.
    I am not sure if I should resolve the symbols by the name shown in dependencywalker or the original name declared in extern "C".

    I am hoping someone might be able to help me.

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi magpielover,

      I see no extort statement, so where do you export the function from the dll? Which compiler was used for creation of the dll?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        magpielover
        wrote on last edited by
        #3

        I am using the below in the common API.h file.
        @#ifndef FEX_API_H
        #define FEX_API_H

        #ifdef WIN32
        #ifndef DLLEXPORT
        #define DLLEXPORT __declspec(dllexport)
        #endif
        #endif

        extern "C" {

        ...
        ....
        typedef int DLLEXPORT (MyPrototype )(double);

        }@

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          You could use nm or dumpbin to see if your symbols are exported correctly.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gedd
            wrote on last edited by
            #5

            You can also try depends
            "Depends":http://dependencywalker.com/

            Gedd

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

              with @ typedef int DLLEXPORT (MyPrototype )(double) @ you export a defined type (function pointer), not a real function.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                you would need the following:

                @
                #ifndef FEX_API_H
                #define FEX_API_H

                #ifdef WIN32

                ifndef DLLEXPORT

                if CREATE_DLL

                define MYDLLAPI __declspec(dllexport)

                else

                define MYDLLAPI __declspec(dllimport)

                endif

                endif

                #endif

                extern "C" {
                ...
                void MYDLLAPI myFunction(int,int);

                }
                @

                CREATE_DLL would be a macro defined inside your dll project but nowhere else.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  magpielover
                  wrote on last edited by
                  #8

                  Hello,
                  I used identifiers in Qlibrary template so sorry for the mistake I made. I have found the solution.
                  I had directly converted the code from VS 6.0 so .def file is used to add the export directive to the object file. However, in the newer versions of compilers such as MinGW and VS 11, __declspec(dllexport) is used to add the export directive automatically. I just added declared the functions with __declspec(dllexport) keyword and problem is solved.

                  This was enough.
                  @#ifdef WIN32
                  #ifdef FEX_CNBCDLL
                  #define DLLEXPORT __declspec(dllexport)
                  #else
                  #define DLLEXPORT __declspec(dllimport)
                  #endif
                  #else
                  #define DLLEXPORT
                  #endif@

                  Thank you all guys. I really appreciate the helpful comments.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mlong
                    wrote on last edited by
                    #9

                    Be sure and add [Solved] to the beginning of the thread title if the issue is solved. Thanks!

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    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