Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

QT Creator - Creating and Using LIBS

  • 21-07-2009 5:14pm
    #1
    Registered Users, Registered Users 2 Posts: 78 ✭✭


    Hi all,

    Firstly, I'm a nooby, so go easy. I'm trying to learn c++ for myself and have chosen the following configuration to get started;
    OS: XP
    toolkit: QT 4.5.1
    IDE: QT Creator 1.2

    Everything is up and running and I've created some *basic* progs.

    However, I'm stuck on the following problem. I wanted to learn how to use libraries. So I created a shared library (called test2library) using the QT Creator wizard and added some silly functionality. Unfortunately, I'm not able to use the linked library in my main project (called imaginatively mainProject).

    // Please also let me know of any bad practice etc. As I said, I'm trying to learn here so all comments welcome in addition to the solution.//

    So my shared library contains four files; test2library.h .cpp .pro and _global.h

    Here are the changes I made to the header and implementation files.


    test2library.h
    #ifndef TEST2LIBRARY_H
    #define TEST2LIBRARY_H
    
    #include "test2Library_global.h"
    #include <qDebug>
    
    class TEST2LIBRARYSHARED_EXPORT Test2Library {
    public:
        Test2Library();
        void doit();
    };
    
    #endif // TEST2LIBRARY_H
    
    

    test2library.cpp
    #include "test2library.h"
    
    
    Test2Library::Test2Library()
    {
    }
    
    void Test2Library::doit()
    {
        qDebug() << "In test2Library";    
    }
    

    OK, everything compiled OK and seems to be running.

    So I go back to my mainProject which is a GUI frame, also with some silly code in it. I open up my mainProject.pro and add the following lines;
    <snip>
    
    INCLUDEPATH += "..\test2Library\test2library"
    LIBS += "..\test2Library\test2library\release\libtest2Library.a"
    
    

    I save everything and rebuild...everything seems fine.

    Then in my mainProject I add the header;
    #include "../test2Library/test2library/test2library.h"
    
    void MainWindow::on_pushButton_clicked()
    {
     qDebug() << "Button pressed!";
     Test2Library *t = new Test2Library();
     t->doit();
    }
    
    

    The program builds fine, but when I run it, I get
    ..../mainProgram.exe exited with code -1073741515
    

    Can anyone give me any helpful pointers. I've searched for solutions but can't seem to find anything that works. I've simplified the entire process as much as possible in order to isolate the problem. It seems that there is a problem with linking the libraries?

    Cheers,
    Mick
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 78 ✭✭floyd.pepper


    OK, so with a couple of hours :( playing around with this...I've found that it's the paths that are giving me trouble.

    If I copy and paste the dll into the same directory as my mainProject.exe it works fine and I can use the functionality in the dll file.

    I've tried numerous combinations of linking to the dynamic library...
    LIBS+= "C:\PathToLibrary\release\libtest2Library.a"  # straight path to *.a file
    
    LIBS+= -LC:\PathToLibrary\release\ -libtest2Library
    
    LIBS+= -LC:\PathToLibrary\release\ -test2Library
    
    LIBS+= -L..\..\PathToLibrary\release\ -libtest2Library # relative path to folder
    

    I've also tried numerous combinations with the INCLUDEPATH.

    ...any ideas?

    Cheers,
    Mick


  • Registered Users, Registered Users 2 Posts: 4,792 ✭✭✭cython


    Ok, first off I'm not familiar with QT Creator as an IDE, but I've seen similar problems with Visual Studio in the past, so any advice is coming from that perspective.

    First off, I think that the directories (LIBS, INCLUDEPATH, etc) that you refer to configuring are for the compiler, and hence will only work for static linking (.LIB files), not DLLs. In fact INCLUDEPATH probably shouldn't be used for libraries at all, but rather for source files that you intend to #include.

    Generall for an EXE to use a DLL, if the EXE is called from the OS directly, the DLL must either be in the same directory, or in a directory that is on the %PATH% variable (in Windows), which you seem to have observed. In order to work around this, VS provides an option on projects for debugging for a "working directory", i.e. it will treat that directory as the location where the EXE is executing, rather than the where the EXE is actually located. If QT Creator provides similar options in a debugger, it might be worth looking into that, otherwise, if you are launching the EXE from a command line, or by double clicking on it, you will likely need to update the PATH, or copy in the DLLS.


  • Registered Users, Registered Users 2 Posts: 78 ✭✭floyd.pepper


    Thanks for getting back to me cython.

    You are dead right. As I already admitted, I'm pretty new to this and still lacking some of the basics. As you point out LIBS and INCLUDEPATH are only used in the compilation phase. The executable doesn't know where the associated dll is hiding.

    As far as I am aware, there are no options to set a 'working directories' in QT Creator, however I may be wrong on that point. The best solution I could come up with was to place the dll in the same folder as the application binary.

    I changed the pro file for the library project so it would do it automatically with each build by setting the DESTDIR variable to point to the mainProject application folder. This works for now, but if this library will be shared by multiple application projects, then I may need to move it to a systems directory or add the location to PATH.

    You can follow the full solution on the QT Centre boards...
    http://www.qtcentre.org/forum/f-newbie-4/t-qt-creator-creating-and-using-libs-22686.html#post110624

    I am now moving onto to bigger and brighter problems...namely signals and slots.

    Cheers,
    Mick


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    QT is great fun to program with. I am on the qt-interest mailing lists. It's a great list to ask questions, experts on it including the trolls themselves.


Advertisement