Results 1 to 5 of 5

Thread: Linking C++ Dll containing class in QT Application

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Linking C++ Dll containing class in QT Application

    Hi,

    I am new to QT development. I have below query.

    I am writing a simple dll in C++ which has a class with member function.

    #DllProg.h
    Qt Code:
    1. class __declspec(dllexport) Funcs
    2. {
    3. public:
    4. Funcs();
    5. void Print();
    6. };
    To copy to clipboard, switch view to plain text mode 
    #DllProg

    Qt Code:
    1. #include "DllProg.h"
    2.  
    3. #include <stdexcept>
    4. #include <iostream>
    5. #include <string>
    6.  
    7. using namespace std;
    8.  
    9. __declspec(dllexport) Funcs::Funcs()
    10. {
    11. cout<<"Funcs : In Constructor"<<endl;
    12. }
    13.  
    14. __declspec(dllexport) void Funcs::Print()
    15. {
    16. cout<<"Print : In DLL";
    17. }
    18.  
    19. extern "C" __declspec(dllexport) Funcs* getObject()
    20. {
    21. cout << "In getObject() "<<endl;
    22. return new Funcs();
    23. }
    To copy to clipboard, switch view to plain text mode 

    #QT Application

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4.  
    5. typedef Funcs* (*pf)();
    6.  
    7. QLibrary myLib("D:\\Practice\\QT\\QTClassApp-build-desktop\\debug\\DllProg.dll");
    8. myLib.load();
    9.  
    10. if(myLib.isLoaded())
    11. {
    12. pf fptr = (pf)myLib.resolve("getObject");
    13. Funcs *s = fptr();
    14.  
    15. printf("getObject Returned - %p" , s);
    16. s->Print();
    17. }
    18. return a.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    Here I am getting Error on statement s->Print();
    getObject() is properly getting called and returning instance of the class. But if I put call to Print its giving Linker Error - undefined reference to `Funcs::Print()'

    #.pro
    win32: LIBS += -L$$PWD/../QTClassApp-build-desktop/debug/ -lDllProg
    INCLUDEPATH += $$PWD/../QTClassApp-build-desktop/debug
    DEPENDPATH += $$PWD/../QTClassApp-build-desktop/debug


    I found the ablove code on QT forum. I am not sure how correct is the code.

    Thanks in Advance.
    Last edited by high_flyer; 5th May 2011 at 14:07. Reason: code tags

Similar Threads

  1. Replies: 10
    Last Post: 20th December 2015, 12:14
  2. Shared Object In Qt and Linking to main application
    By Ashutosh2k1 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 11:36
  3. Linking error when using library in other application
    By JPNaude in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2010, 10:20
  4. Static Linking Application for Realease
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 19:12
  5. Replies: 2
    Last Post: 1st August 2007, 16:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.