Results 1 to 2 of 2

Thread: Linking DLL aganist qt application in windows

  1. #1
    Join Date
    Jun 2015
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Linking DLL aganist qt application in windows

    Hi,
    I have created a shared library in qt and a sample application to test the library functions. But when i try to link the dll file, only single function is accessible other functions are not.Below is my library and application code snippet. how can i change the code to access the library function ?

    Library Header file:

    #ifndef TEST_LIB_H
    #define TEST_LIB_H
    #include <QtCore/qglobal.h>

    #if defined(TEST_LIB_LIBRARY)
    # define TEST_LIBSHARED_EXPORT Q_DECL_EXPORT
    #else
    # define TEST_LIBSHARED_EXPORT Q_DECL_IMPORT
    #endif

    class TEST_LIBSHARED_EXPORT Test_lib {
    public:
    Test_lib();
    };

    extern "C" TEST_LIBSHARED_EXPORT int add(int a,int b);
    extern "C" TEST_LIBSHARED_EXPORT int sub(int a,int b);

    #endif // TEST_LIB_H


    Libray source file:

    #include "test_lib.h"
    #include "stdio.h"

    Test_lib::Test_lib()
    {
    printf("Test Lib Invoked\n");
    }
    extern "C" TEST_LIBSHARED_EXPORT int add(int a, int b)
    {
    printf("In Lib\n add");
    int c=a+b;
    return c;
    }

    extern "C" TEST_LIBSHARED_EXPORT int sub(int a, int b)
    {
    printf("In Lib\n sub");
    return 2;
    // int c=a-b;
    //return c;
    }


    Application header file:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "test_lib.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;

    private slots:
    void on_pushButton_clicked();
    };


    #endif // MAINWINDOW_H

    Application source file:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QLibrary"
    #include "QDebug"
    #include "QMessageBox"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    int result=0;
    result=add(1,2);
    qDebug() << result;
    result=sub(2,1);
    qDebug() << result;
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }


    My problem is add function is accessible but sub function is not accessible.
    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking DLL aganist qt application in windows

    How have you linked the test library to the main program? What does the main program pro file look like?

Similar Threads

  1. Replies: 3
    Last Post: 7th February 2012, 10:40
  2. Replies: 2
    Last Post: 25th November 2009, 23:44
  3. Linking Windows
    By dark1988 in forum Newbie
    Replies: 2
    Last Post: 3rd July 2008, 09:32
  4. Linking QT 3.3 in windows
    By siddharth_univ in forum Installation and Deployment
    Replies: 10
    Last Post: 26th February 2007, 06:38

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.