Results 1 to 9 of 9

Thread: Deploying an app with additional library

  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Deploying an app with additional library

    I am getting back to work on my project and as the first thing I would like to make it able to use additional library placed in external dll file. In other words I am trying to deploy dynamic linked application.

    Unfortunately, after reading several different articles and threads I am a little bit confused about what I should do.

    http://doc.qt.nokia.com/4.7-snapshot/sharedlibrary.html
    http://techbase.kde.org/Policies/Bin...ssues_With_C++

    Currently I am reading these two articles and I already know that I should focus on shared libraries because they are in fact DLL (or rather DLL are Microsoft's idea for that).

    And to the project itself, I am adding now chunks of the code as mentioned in the first article in this paragraph -> "In each header of the library, we specify the following:".

    By the way I am already having dll file. But I assume my Qt is statically built and somehow I remember that it is impossible to make dynamically linked application when using Qt built like this, am I right ?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  2. #2
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Deploying an app with additional library

    Nevermind, this is about the previous post I wrote.

    I have my program compiled with qmake, and I just found in documentation that the only way to add library to it is to make static library (just look for "Adding libraries in qmake projects" in Google, I found it via assistant built in QtCreator). From that comes my question.

    Static library requires rebuilding whole application, when adding new functionality, or updating the library, to the library. Is this statement correct ? Because I am pretty sure that dynamic linked libraries do not require it, when adding some new functionality to library I am bound only to deploy new version of the dll file, right ?

    All these question comes from my confusion, as I have spent whole day reading about it and trying to explain it by myself. And I am just trying to help myself to provide updates to the application not by recompiling it but by releasing new versions of my library.
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Deploying an app with additional library

    Yes with statically compiled program compiler tends (actually must) to recompile everything, even if only small portion of small dll was changed. Of course you can use precompiled headers etc.. to speed that process up.
    In dynamic linked program "You actually end up" with program + program (dll) and if You extend functionality in function that program uses in Your dll then You only need to recompile dll <- that's the key concept of dll, to have easy ability to update program for new functionality "fast" (in sense of compiling time) - also this saves memory, because dll is loaded only when it's needed.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  4. #4
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Deploying an app with additional library

    so actually I need to do what ?
    because honestly, at the moment, I do not know

    The documentation shows qmake handled project to be used only with statically linked libraries, so do I need to change compiler ?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  5. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Deploying an app with additional library

    That depends on what You want to do .

    No You don't need to change compiler.

    If You wrote Your dll and want it to be linked statically into the program code then add it into project file (.pro) like this:
    Qt Code:
    1. LIBS += -L/path/to/lib -lLibName
    To copy to clipboard, switch view to plain text mode 
    and use exposed function (include .h file with function definition) from within your program. Then use class from the library as any other class.

    If You want it to be dynamically linked then use QLIbrary and load library at particular time, when function from library is needed, something along these lines:
    Qt Code:
    1. void myClass::doSomething() {
    2. QLibrary tessLib("qLibT.dll");
    3. tessLib.load();
    4.  
    5. if( tessLib.isLoaded() )
    6. {
    7. qDebug() << "Lib loaded succesful: " << tessLib.errorString();
    8. }else{
    9. qDebug() << "Error lib load: " << tessLib.errorString();
    10. return false;
    11. }
    12.  
    13. tessDllBeginPage = (TessDllBeginPage) tessLib.resolve( "TessDllBeginPage" );
    14.  
    15. if(tessDllBeginPage){
    16. qDebug() << "tessDllBeginPage useful!!! GOOD" << tessLib.errorString();
    17. }else{
    18. qDebug() << "tessDllBeginPage not resolved!" << tessLib.errorString();
    19. return false;
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  6. #6
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Deploying an app with additional library

    but in Your example You are trying to resole particular method, right ?
    How about creating an object of the class defined and declared in the library ?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  7. #7
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Deploying an app with additional library

    In above example I resolve functions from dll in i.e. constructor of my main program class (i.e. void myProgramMainClass::initLib() ).
    Qt Code:
    1. tessDllBeginPage = (TessDllBeginPage) tessLib.resolve( "TessDllBeginPage" );
    To copy to clipboard, switch view to plain text mode 
    tessDllBeginPage is of type TessDllBeginPage* and declared in private section of this class, so I can use tessDllBeginPage anywhere in my class.
    Usage:
    .h private section
    Qt Code:
    1. typedef int (*TessDllBeginPageUprightBPP)(uinT32 xsize,
    2. uinT32 ysize,
    3. unsigned char *buf,
    4. const char* lang,
    5. uinT8 bpp);
    6. TessDllBeginPageUprightBPP tessDllBeginPageUprightBPP;
    To copy to clipboard, switch view to plain text mode 
    .cpp use function from dll
    Qt Code:
    1. qDebug() << tessDllBeginPageUprightBPP( (uinT32)tmpPix.width(), (uinT32)tmpPix.height(),
    2. tmpPix.bits(),
    3. "eng",
    4. (uinT8)tmpPix.depth() );
    To copy to clipboard, switch view to plain text mode 
    I posted different function (I actually didn't use earlier posted) but You will get basic idea how to use it.
    Or, to answer your question, example with popler dll:
    .pro file
    Qt Code:
    1. LIBS += -llibpoppler-qt4
    To copy to clipboard, switch view to plain text mode 
    .h private
    Qt Code:
    1. Poppler::Document *document;
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. Poppler::Document *pdfDoc = Poppler::Document::loadFromData( baPdf );
    To copy to clipboard, switch view to plain text mode 

    See this, that will help you:
    http://doc.qt.nokia.com/qtcreator-2....libraries.html
    Last edited by Talei; 10th July 2011 at 00:04. Reason: updated contents
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  8. #8
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Deploying an app with additional library

    so all I need to do is to exposed the constructor with proper macro, not the class itself,
    like here ?

    and load the library right before creating the object of the class...

    I am going to try it

    one more question about "Typically, clients will include only the public header files of shared libraries." -
    the public header is the one without _global suffix ? I created the shared library project using wizard in qt and it made for me 2 headers:
    - mylib.h
    - mylib_global.h

    and and the tutorial says about including the public header of the library, but I assume it is the one without global at the end.

    Nevertheless I was given with the link about adding libraries to the project...but...the only file I can add are those with the .lib extension....the problem is I have no such file created after compiling the library...all I have are .a and .dll file
    Last edited by kornicameister; 10th July 2011 at 11:18.
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  9. #9
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Deploying an app with additional library

    alright it's time to get out from confusion...
    I still can not get all working, but after constantly reading and reading, I found this article http://developer.qt.nokia.com/forums/viewthread/6433

    basing on it, what I need is to have something usable like for example usage of mysql in qt projects, where I include one some headers but basically I need to deliver an dll to release version ? But I am afraid it may consider plugins...but I will not verify here anything, because I lost all clear thinking

    hope that will make my idea more clear...because honestly web is full of different approaches which differs from each other and I do not know what to do know, even the help which Talei has offered was not really helpful because clearly even me don't understand how it should works.

    Nevertheless my goal is as presented above...and I only need some guidance.
    Basically I know I will have to provide some headers to the client. But let's focus on the library itself. So far, I've created the shared library project in qt creator...very simple, just for educational purpose

    the codes

    TestProjectLib.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-07-10T11:40:27
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT -= gui
    8.  
    9. TARGET = TestProjectLib
    10. TEMPLATE = lib
    11. CONFIG += dll #added manually
    12.  
    13. DEFINES += TESTPROJECTLIB_LIBRARY
    14.  
    15. SOURCES += testprojectlib.cpp \
    16. summator.cpp
    17.  
    18. HEADERS += testprojectlib.h\
    19. TestProjectLib_global.h \
    20. summator.h
    21.  
    22. symbian {
    23. #Symbian specific definitions
    24. MMP_RULES += EXPORTUNFROZEN
    25. TARGET.UID3 = 0xE14FD6C2
    26. TARGET.CAPABILITY =
    27. TARGET.EPOCALLOWDLLDATA = 1
    28. addFiles.sources = TestProjectLib.dll
    29. addFiles.path = !:/sys/bin
    30. DEPLOYMENT += addFiles
    31. }
    32.  
    33. unix:!symbian {
    34. maemo5 {
    35. target.path = /opt/usr/lib
    36. } else {
    37. target.path = /usr/local/lib
    38. }
    39. INSTALLS += target
    40. }
    To copy to clipboard, switch view to plain text mode 

    TestProjectLib.h
    Qt Code:
    1. #ifndef TESTPROJECTLIB_H
    2. #define TESTPROJECTLIB_H
    3.  
    4. #include "TestProjectLib_global.h"
    5.  
    6. class TESTPROJECTLIBSHARED_EXPORT TestProjectLib {
    7. public:
    8. TestProjectLib();
    9. };
    10.  
    11. #endif // TESTPROJECTLIB_H
    To copy to clipboard, switch view to plain text mode 

    TestProjectLib_global.h
    Qt Code:
    1. #ifndef TESTPROJECTLIB_GLOBAL_H
    2. #define TESTPROJECTLIB_GLOBAL_H
    3.  
    4. #include <QtCore/qglobal.h>
    5.  
    6. #if defined(TESTPROJECTLIB_LIBRARY)
    7. # define TESTPROJECTLIBSHARED_EXPORT Q_DECL_EXPORT
    8. #else
    9. # define TESTPROJECTLIBSHARED_EXPORT Q_DECL_IMPORT
    10. #endif
    11.  
    12. #endif // TESTPROJECTLIB_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 

    and I have an additional class where I put some trivial functionality
    Qt Code:
    1. #ifndef SUMMATOR_H
    2. #define SUMMATOR_H
    3.  
    4. #include <QObject>
    5. #include <TestProjectLib_global.h>
    6.  
    7. class TESTPROJECTLIBSHARED_EXPORT Summator : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit TESTPROJECTLIBSHARED_EXPORT Summator(QObject *parent = 0);
    12.  
    13. double TESTPROJECTLIBSHARED_EXPORT summatorMe(int loops, int number);
    14. private:
    15. int loops;
    16. };
    17.  
    18. #endif // SUMMATOR_H
    To copy to clipboard, switch view to plain text mode 

    this concept presents the concept I want to use the library in my application, which means creating the class' objects like this
    Qt Code:
    1. MyClass *obj = new MyClass()
    To copy to clipboard, switch view to plain text mode 
    and not by using some weird constructions with QLibrary

    maybe this can help us to help me
    Last edited by kornicameister; 10th July 2011 at 17:22.
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. QMenu with a additional QPushButton
    By seux in forum Newbie
    Replies: 3
    Last Post: 4th June 2011, 07:25
  2. Microsoft Visual C++- Runtime Library Error while deploying Qt Application
    By mammaiap in forum Installation and Deployment
    Replies: 1
    Last Post: 7th May 2011, 01:41
  3. Problem deploying a two library + executable application to windows
    By joseprl89 in forum Installation and Deployment
    Replies: 8
    Last Post: 15th March 2011, 21:52
  4. QT Creator and additional library
    By banita in forum Qt Tools
    Replies: 4
    Last Post: 7th September 2010, 15:37
  5. Additional Library Directories Not Searched
    By TheGrimace in forum General Programming
    Replies: 1
    Last Post: 11th September 2007, 16:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.