Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Issue linking .lib or .dll for usage in .cpp
Forum Updated to NodeBB v4.3 + New Features

Issue linking .lib or .dll for usage in .cpp

Scheduled Pinned Locked Moved Solved Qt 6
13 Posts 4 Posters 1.4k Views 2 Watching
  • 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.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #4

    When you really include Fwlib32.h with extern "C" everywhere then you should not get warnings about missing __imp_FOO functions when I'm correct.
    Make sure to add the guard everywhere. Also please post the linker error with the full name of the function.

    /edit: You're using MinGW? Right? Then try to link directly against the dll instead the lib - MinGW can't do anything with the static import lib for MSVC but has the ability to directly link against C dlls since some years iirc.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    O 2 Replies Last reply
    1
    • Christian EhrlicherC Christian Ehrlicher

      When you really include Fwlib32.h with extern "C" everywhere then you should not get warnings about missing __imp_FOO functions when I'm correct.
      Make sure to add the guard everywhere. Also please post the linker error with the full name of the function.

      /edit: You're using MinGW? Right? Then try to link directly against the dll instead the lib - MinGW can't do anything with the static import lib for MSVC but has the ability to directly link against C dlls since some years iirc.

      O Offline
      O Offline
      orsini29
      wrote on last edited by
      #5

      @Christian-Ehrlicher

      The full error(s) here:

      debug/mainwindow.o: in function `MainWindow::MainWindow(QWidget*)':
      
      C:\Users\Sorsini\Documents\Qt Prototypes\Test\build-Test-Desktop_Qt_6_2_3_MinGW_64_bit-Debug/../Test/mainwindow.cpp:13: undefined reference to `__imp_cnc_mdg_moniclear'
      
      collect2.exe: error: ld returned 1 exit status
      
      [Makefile.Debug:73: debug/Test.exe] Error 1
      

      I went ahead and put the extern "C" {#include "Fwlib32.h"} around where I am including the .h file, and this is the only place I include it, which is in mainwindow.cpp.

      Could this be an issue with how I am initializing the LIBS and INCLUDEPATH variables within the *.pro file?

      1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        When you really include Fwlib32.h with extern "C" everywhere then you should not get warnings about missing __imp_FOO functions when I'm correct.
        Make sure to add the guard everywhere. Also please post the linker error with the full name of the function.

        /edit: You're using MinGW? Right? Then try to link directly against the dll instead the lib - MinGW can't do anything with the static import lib for MSVC but has the ability to directly link against C dlls since some years iirc.

        O Offline
        O Offline
        orsini29
        wrote on last edited by orsini29
        #6

        @Christian-Ehrlicher Yes I am using MinGW. So instead of in the .pro file having

        win32:LIBS += C:/DLL/Fwlib32.lib
        
        // Change it to the following
        
        win32:LIBS += C:/DLL/Fwlib32.dll
        

        Also, how would I verify that I am using MinGW? I am almost sure that I am, as when I go to the bottom where the errors are I right click and press 'Show Output', which takes me to the compile output, and I see this for my Makefile, making me believe I am using MinGW.

        C:/Qt/Tools/mingw900_64/bin/mingw32-make -f Makefile.Debug
        

        Edit: So I changed around my .pro file to mimic what you had said about the .dll instead of the .lib. When I did that, I receievd a new error which was

        collect2.exe: error: ld returned 5 exit status
        

        I saw on stackoverflow that adding this to the .pro file helped someone mitigate the issue

        mingw {
                contains(QT_ARCH, x86_64): {
                    LIBS+=-Wl,--no-gc-sections
                }
        }
        

        Which now I received a
        Failed to start program. Path or permissions wrong?

        I know that the path is there, and that the files I am looking for are as well there...

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @orsini29 said in Issue linking .lib or .dll for usage in .cpp:

          x86_64

          So you're using a 64Bit Qt? The library seems to be a 32bit one (when I interpret Fwlib32 correct) - you can't mix them.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          O 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @orsini29 said in Issue linking .lib or .dll for usage in .cpp:

            x86_64

            So you're using a 64Bit Qt? The library seems to be a 32bit one (when I interpret Fwlib32 correct) - you can't mix them.

            O Offline
            O Offline
            orsini29
            wrote on last edited by
            #8

            @Christian-Ehrlicher

            I can not believe that slipped my mind... So if I download the 32 bit version, and then configure the .pro file the same as above, minus

            mingw {
                    contains(QT_ARCH, x86_64): {
                        LIBS+=-Wl,--no-gc-sections
                    }
            }
            

            You think that would be the solution?

            1 Reply Last reply
            0
            • hskoglundH Online
              hskoglundH Online
              hskoglund
              wrote on last edited by
              #9

              Hi, I just tested for you :-) ir's pretty easy to find fwlib32 from FOCAS on google

              Using a Qt version 6 then it's much more difficult to build for 32-bit dlls.
              So instead I recommend you downgrade to Qt 5, I just tried Qt 5.15.2 and MinGW 8.1 32-bit version.
              First, make an empty vanilla widgets app.
              Add this line to your .pro file:

              LIBS += C:/DLL/fwlib32.lib
              

              Edit your mainwindow.cpp file to look like this:

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              
              #include "C:/DLL/fwlib32.h"
              
              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                  cnc_mdg_moniclear(1);
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              

              compile and build it in Release mode.
              Then to test, make sure to copy the fwlib32.dll to the same directory as the .exe file.
              Good luck!

              O 2 Replies Last reply
              2
              • hskoglundH hskoglund

                Hi, I just tested for you :-) ir's pretty easy to find fwlib32 from FOCAS on google

                Using a Qt version 6 then it's much more difficult to build for 32-bit dlls.
                So instead I recommend you downgrade to Qt 5, I just tried Qt 5.15.2 and MinGW 8.1 32-bit version.
                First, make an empty vanilla widgets app.
                Add this line to your .pro file:

                LIBS += C:/DLL/fwlib32.lib
                

                Edit your mainwindow.cpp file to look like this:

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                
                #include "C:/DLL/fwlib32.h"
                
                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                    cnc_mdg_moniclear(1);
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                

                compile and build it in Release mode.
                Then to test, make sure to copy the fwlib32.dll to the same directory as the .exe file.
                Good luck!

                O Offline
                O Offline
                orsini29
                wrote on last edited by orsini29
                #10

                @hskoglund Awesome! I am going to try that now. Thanks so much, seriously. I have been banging my head against the wall on this over a week now. I couldn't find version 5.15.2, but I did find 5.0.3. Is just the MinGW the 32 bit version? I can't seem to find a Qt Creator in 32 bit version.... Thanks again :D

                Edit: Nevermind...I found the 5.15.2 version and the MinGW 8.1 32 bit..I will be testing it out shortly! Thanks again @hskoglund

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Hi,

                  There's no need for Qt Creator's architecture to match the architecture of the Qt version you use for your project.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • hskoglundH hskoglund

                    Hi, I just tested for you :-) ir's pretty easy to find fwlib32 from FOCAS on google

                    Using a Qt version 6 then it's much more difficult to build for 32-bit dlls.
                    So instead I recommend you downgrade to Qt 5, I just tried Qt 5.15.2 and MinGW 8.1 32-bit version.
                    First, make an empty vanilla widgets app.
                    Add this line to your .pro file:

                    LIBS += C:/DLL/fwlib32.lib
                    

                    Edit your mainwindow.cpp file to look like this:

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    
                    #include "C:/DLL/fwlib32.h"
                    
                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                        cnc_mdg_moniclear(1);
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    

                    compile and build it in Release mode.
                    Then to test, make sure to copy the fwlib32.dll to the same directory as the .exe file.
                    Good luck!

                    O Offline
                    O Offline
                    orsini29
                    wrote on last edited by
                    #12

                    @hskoglund

                    I just tested out your answer, and it worked like a charm. Thank you so much for your assistance! It is very appreciated :)

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      orsini29
                      wrote on last edited by
                      #13
                      This post is deleted!
                      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