Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to link an .obj-File in the build process of Qt (qmake)

How to link an .obj-File in the build process of Qt (qmake)

Scheduled Pinned Locked Moved Solved General and Desktop
link errorlink .obj file
13 Posts 4 Posters 7.3k Views
  • 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.
  • K karlheinzreichel
    27 Feb 2018, 14:15

    How does your project file looks like ?

    regards
    karl-heinz

    M Offline
    M Offline
    MarekG
    wrote on 27 Feb 2018, 14:17 last edited by
    #4

    @karlheinzreichel

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += main.cpp
    
    DISTFILES += \
        gpib-32.obj
    
    HEADERS += \
        ni488.h
    
    1 Reply Last reply
    0
    • A aha_1980
      27 Feb 2018, 14:16

      Hi @MarekG, yes you need to link to ni4882.obj. If you use a 32-bit compiler then you need to link against a 32 bit object file.

      I have done this a long time ago, and I successfully used the following link command for MSVC in my project.pro file:

      QMAKE_LIBDIR += /path/to/objectfile
      LIBS += ni4882.obj
      

      However, this is not the recommended way, which would be:

      LIBS += -L/path/to/objectfile -lni4882
      

      To get this to link I had to rename ni4882.obj to ni4882.lib, and I have not tested this version yet.

      Edit: version 2 works.

      M Offline
      M Offline
      MarekG
      wrote on 27 Feb 2018, 14:42 last edited by
      #5

      @aha_1980
      Okay, again a bit slower.
      I have to rename my gpib-32.obj to gpib-32.lib and then add it as a library?
      That doesn't help.

      You talked about the ni4882.obj. I have that as well together with nisyscfg.lib. But changing ni4882.obj to ni4882.lib and adding this doesn't help as well. For that I created another project and included ni4882.h and used the same code.

      A 1 Reply Last reply 27 Feb 2018, 14:46
      0
      • M MarekG
        27 Feb 2018, 14:42

        @aha_1980
        Okay, again a bit slower.
        I have to rename my gpib-32.obj to gpib-32.lib and then add it as a library?
        That doesn't help.

        You talked about the ni4882.obj. I have that as well together with nisyscfg.lib. But changing ni4882.obj to ni4882.lib and adding this doesn't help as well. For that I created another project and included ni4882.h and used the same code.

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 27 Feb 2018, 14:46 last edited by aha_1980
        #6

        Hi @MarekG,

        @aha_1980
        Okay, again a bit slower.

        Well...

        I have to rename my gpib-32.obj to gpib-32.lib and then add it as a library?
        That doesn't help.

        I didn't use gpib-32 but used ni4882 instead. Don't know if there is much difference.

        You talked about the ni4882.obj. I have that as well together with nisyscfg.lib. But changing ni4882.obj to ni4882.lib and adding this doesn't help as well. For that I created another project and included ni4882.h and used the same code.

        How did you add it? When I added the line LIBS += -L/path/to/objectfile -lni4882 in my pro file it only worked for me if I renamed ni4882.obj to ni4882.lib.

        Which error do you get? (Or better: post the compiler and linker commands from the compile output).

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MarekG
          wrote on 27 Feb 2018, 14:52 last edited by
          #7

          Hi @aha_1980 ,

          okay, I made a new Project with ni4882.h

          #include <QCoreApplication>
          #include <windows.h>
          #include "ni4882.h"
          
          int main(int argc, char *argv[])
          {
              QCoreApplication a(argc, argv);
              unsigned int test;
              test = ibconfig (1,2,3);
          
              return a.exec();
          }
          

          And my project file:

          QT -= gui
          
          CONFIG += c++11 console
          CONFIG -= app_bundle
          
          # The following define makes your compiler emit warnings if you use
          # any feature of Qt which as been marked deprecated (the exact warnings
          # depend on your compiler). Please consult the documentation of the
          # deprecated API in order to know how to port your code away from it.
          DEFINES += QT_DEPRECATED_WARNINGS
          
          # You can also make your code fail to compile if you use deprecated APIs.
          # In order to do so, uncomment the following line.
          # You can also select to disable deprecated APIs only up to a certain version of Qt.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          SOURCES += main.cpp \
              main.cpp
          
          HEADERS += \
              ni4882.h
          
          LIBS += -L/. -lni4882
          

          I also tried to add the library by right click and "Add library". But it doesn't change anything.

          Still the same Linker Error: LNK2019 unresolved external symbol _ibconfig@12 referenced in function _main

          A 1 Reply Last reply 27 Feb 2018, 14:56
          0
          • M MarekG
            27 Feb 2018, 14:52

            Hi @aha_1980 ,

            okay, I made a new Project with ni4882.h

            #include <QCoreApplication>
            #include <windows.h>
            #include "ni4882.h"
            
            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
                unsigned int test;
                test = ibconfig (1,2,3);
            
                return a.exec();
            }
            

            And my project file:

            QT -= gui
            
            CONFIG += c++11 console
            CONFIG -= app_bundle
            
            # The following define makes your compiler emit warnings if you use
            # any feature of Qt which as been marked deprecated (the exact warnings
            # depend on your compiler). Please consult the documentation of the
            # deprecated API in order to know how to port your code away from it.
            DEFINES += QT_DEPRECATED_WARNINGS
            
            # You can also make your code fail to compile if you use deprecated APIs.
            # In order to do so, uncomment the following line.
            # You can also select to disable deprecated APIs only up to a certain version of Qt.
            #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
            
            SOURCES += main.cpp \
                main.cpp
            
            HEADERS += \
                ni4882.h
            
            LIBS += -L/. -lni4882
            

            I also tried to add the library by right click and "Add library". But it doesn't change anything.

            Still the same Linker Error: LNK2019 unresolved external symbol _ibconfig@12 referenced in function _main

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 27 Feb 2018, 14:56 last edited by aha_1980
            #8

            @MarekG said in How to link an .obj-File in the build process of Qt (qmake):

            LIBS += -L/. -lni4882

            Where is your ni4882.lib located? In the source directory? That does not help for shadow builds :(

            Try:

            LIBS += -L$$PWD -lni4882

            It must work :)

            Qt has to stay free or it will die.

            M 1 Reply Last reply 27 Feb 2018, 15:05
            1
            • A aha_1980
              27 Feb 2018, 14:56

              @MarekG said in How to link an .obj-File in the build process of Qt (qmake):

              LIBS += -L/. -lni4882

              Where is your ni4882.lib located? In the source directory? That does not help for shadow builds :(

              Try:

              LIBS += -L$$PWD -lni4882

              It must work :)

              M Offline
              M Offline
              MarekG
              wrote on 27 Feb 2018, 15:05 last edited by
              #9

              @aha_1980 And again :(

              I tried

              LIBS += -L$$PWD -lni4882
              

              -> It didn't work.

              I tried to copy the lib-file into the debug folder -> It didn't work.
              I tried to add it by right click when it's in the debug folder:

              win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/ -lni4882
              else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/ -lni4882
              
              INCLUDEPATH += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug
              DEPENDPATH += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug
              
              win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/libni4882.a
              else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/libni4882.a
              else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/ni4882.lib
              else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/ni4882.lib
              

              And when it's in the source directory:

              win32: LIBS += -L$$PWD/./ -lni4882
              
              INCLUDEPATH += $$PWD/.
              DEPENDPATH += $$PWD/.
              
              win32:!win32-g++: PRE_TARGETDEPS += $$PWD/./ni4882.lib
              else:win32-g++: PRE_TARGETDEPS += $$PWD/./libni4882.a
              

              But nothing helps :(

              A 1 Reply Last reply 27 Feb 2018, 15:09
              0
              • M MarekG
                27 Feb 2018, 15:05

                @aha_1980 And again :(

                I tried

                LIBS += -L$$PWD -lni4882
                

                -> It didn't work.

                I tried to copy the lib-file into the debug folder -> It didn't work.
                I tried to add it by right click when it's in the debug folder:

                win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/ -lni4882
                else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/ -lni4882
                
                INCLUDEPATH += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug
                DEPENDPATH += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug
                
                win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/libni4882.a
                else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/libni4882.a
                else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/release/ni4882.lib
                else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-test_dg2030_1-Desktop_Qt_5_10_1_MSVC2015_32bit-Debug/debug/ni4882.lib
                

                And when it's in the source directory:

                win32: LIBS += -L$$PWD/./ -lni4882
                
                INCLUDEPATH += $$PWD/.
                DEPENDPATH += $$PWD/.
                
                win32:!win32-g++: PRE_TARGETDEPS += $$PWD/./ni4882.lib
                else:win32-g++: PRE_TARGETDEPS += $$PWD/./libni4882.a
                

                But nothing helps :(

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 27 Feb 2018, 15:09 last edited by
                #10

                @MarekG

                No, much to complicated - it's really that simple as I posted.

                Please post the compiler&linker output -> we need to know where the linker is searching for the additional files.

                And one hint: avoid '/' at the end of a path -> it converts to a backslash in Windows and I have seen strange things happen.

                I need to leave now. Good luck!

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MarekG
                  wrote on 27 Feb 2018, 15:28 last edited by
                  #11

                  @aha_1980

                  Okay, I don't know what happened, but I created another project and tried everything again. It worked now without any error :)

                  So to summarize: I included "ni4882.h" and added the library "ni4882.lib" (renamed from ni4882.obj)

                  Thank you everyone for your help ;)

                  1 Reply Last reply
                  3
                  • M Offline
                    M Offline
                    mranger90
                    wrote on 27 Feb 2018, 18:39 last edited by
                    #12

                    Does adding something like this to your profile work ?

                    OBJECTS_DIR += $$PWD
                    OBJECTS += objtest.o
                    

                    Obviously I tried this on Linux, so drop the ".o" and you may need to replace it with ".obj"

                    A 1 Reply Last reply 28 Feb 2018, 19:56
                    0
                    • M mranger90
                      27 Feb 2018, 18:39

                      Does adding something like this to your profile work ?

                      OBJECTS_DIR += $$PWD
                      OBJECTS += objtest.o
                      

                      Obviously I tried this on Linux, so drop the ".o" and you may need to replace it with ".obj"

                      A Offline
                      A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on 28 Feb 2018, 19:56 last edited by
                      #13

                      @mranger90 said in How to link an .obj-File in the build process of Qt (qmake):

                      Does adding something like this to your profile work ?

                      OBJECTS_DIR += $$PWD
                      OBJECTS += objtest.o
                      

                      Obviously I tried this on Linux, so drop the ".o" and you may need to replace it with ".obj"

                      Hi @mranger90,

                      ni4882.obj is not really a object, but a linker input file. The real functions are in ni4882.dll. So using LIBS is the correct way, the only strange thing is that the linker input file uses the extension .obj. But this can easily be fixed by renaming.

                      Regards.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1

                      13/13

                      28 Feb 2018, 19:56

                      • Login

                      • Login or register to search.
                      13 out of 13
                      • First post
                        13/13
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved