How to link an .obj-File in the build process of Qt (qmake)
-
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
-
@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.
-
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).
-
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
-
@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 :)
-
@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 :(
-
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!
-
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 ;)
-
@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.