how to statically link .a to qt (solved)
-
i have a static file called libQLoglib.a, like to know how to statically link and use the library.
I just inserted the line below into project file
LIBS +=-l libQLogLib -
In Project, i insert
INCLUDEPATH += /myDir //where myfile.a is LIBS += -l myfile.a My IDE error: cannot find Lib collect2: error: ld returned 1 exit status
@houmingc Hmmm... I think it sould be a code like this:
LIBS += -L./myDir -lmyfile
INCLUDEPATH is to find include files (.h) and LIBS to find libraries and its paths.
Don't write a blank space between
-l
and your lib or between-L
and your lib path.BTW, following your example, it seems myDir is in the root filesystem. Is that right? I suppose no.
-
Files is not in root file system. Below is what i did:
Compiler error:
cannot find -llibQLogLib
error: ld returned 1 exit addressAssuming libQLogLib.a is in folder home/git1/TrainKochi33
I insert the line below in Pro fileLIBS += -L/home/git1/TrainKochi33 -llibQLogLib
or
LIBS += -llibQLogLibI insert all the header files and use the function in the lib as per normal.
Then i rebuild, run qmake and run.
Please kindly assist, what when wrong. -
Files is not in root file system. Below is what i did:
Compiler error:
cannot find -llibQLogLib
error: ld returned 1 exit addressAssuming libQLogLib.a is in folder home/git1/TrainKochi33
I insert the line below in Pro fileLIBS += -L/home/git1/TrainKochi33 -llibQLogLib
or
LIBS += -llibQLogLibI insert all the header files and use the function in the lib as per normal.
Then i rebuild, run qmake and run.
Please kindly assist, what when wrong. -
@houmingc As I said before, you don't need to put the text "lib" if the library begins with those letters.
So in your case, you should write the next line:
LIBS += -L/home/git1/TrainKochi33 -lQLogLib
Sir, static library name itself is libQLogLib.
Initially a third-party pass me .c and .h files
I compile them with error, in the end i ask them for .a file.
Now i can't static link them into my GUI.Below is my pro file
QT += core gui QT += network QT +=gui QT +=gui declarative QT += widgets QT += multimedia QT += multimediawidgets QT += xml greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = TrainKochi33 TEMPLATE = app CONFIG += c++11 #CONFIG += -static libQLogLib win32:LIBS += -lrt SOURCES += main.cpp\ mainwindow.cpp \ threada.cpp \ mytimer.cpp \ functions.cpp \ i2c.cpp HEADERS += mainwindow.h \ threada.h \ mytimer.h \ functions.h \ i2c.h \ includes.h \ CLogMsgQ.h \ CMsgQ.h \ Common_Logging.h #INCLUDEPATH += libQLogLib.a LIBS += -L\home\git1\TrainKochi33 -llibQLogLib FORMS += mainwindow.ui #DISTFILES += \ # libQLogLib.a #INCLUDEPATH += /home/git1/TrainKochi33 #CONFIG += libQLogLib.a
-
Sir, static library name itself is libQLogLib.
Initially a third-party pass me .c and .h files
I compile them with error, in the end i ask them for .a file.
Now i can't static link them into my GUI.Below is my pro file
QT += core gui QT += network QT +=gui QT +=gui declarative QT += widgets QT += multimedia QT += multimediawidgets QT += xml greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = TrainKochi33 TEMPLATE = app CONFIG += c++11 #CONFIG += -static libQLogLib win32:LIBS += -lrt SOURCES += main.cpp\ mainwindow.cpp \ threada.cpp \ mytimer.cpp \ functions.cpp \ i2c.cpp HEADERS += mainwindow.h \ threada.h \ mytimer.h \ functions.h \ i2c.h \ includes.h \ CLogMsgQ.h \ CMsgQ.h \ Common_Logging.h #INCLUDEPATH += libQLogLib.a LIBS += -L\home\git1\TrainKochi33 -llibQLogLib FORMS += mainwindow.ui #DISTFILES += \ # libQLogLib.a #INCLUDEPATH += /home/git1/TrainKochi33 #CONFIG += libQLogLib.a
@houmingc Perhaps I didn't explain myself properly.
If the library is named
libXXX.a
orlibXXX.so
, you don't need to put thelib
prefix in your qmake or Makefile.More info here:
http://stackoverflow.com/questions/6231206/lib-prefix-on-libraries
Besides, you pro file has a wrong line. Change this one:
LIBS += -L\home\git1\TrainKochi33 -llibQLogLib
And use this one instead:
LIBS += -L/home/git1/TrainKochi33 -lQLogLib
-
Hi, I do it this way (i'm working on unix):
unix:!macx: LIBS += -L$$PWD/../../Project1/Release/ -libOne INCLUDEPATH += $$PWD/../../LibOne DEPENDPATH += $$PWD/../../LibOne/Release unix:!macx: PRE_TARGETDEPS += $$PWD/../../Project1/Release/libOne.a
I use all this 4 lines for every lib I need. In this case my lib is named "libOne.a" and my paths structure is something like this: ( so you can understand it better)
workspace (folder) |-----QtProject (folder) | |-Myproject (folder) | |- MyProject.exe // so from here u have to go up 2 steps (that's why I have "$$PWD/../../" |-----LibOne (Folder) | |-Release (folder) | | |- libOne.a (The file I want) | |- Debug (folder) ...
Hope it helps you.
-
Hi, I do it this way (i'm working on unix):
unix:!macx: LIBS += -L$$PWD/../../Project1/Release/ -libOne INCLUDEPATH += $$PWD/../../LibOne DEPENDPATH += $$PWD/../../LibOne/Release unix:!macx: PRE_TARGETDEPS += $$PWD/../../Project1/Release/libOne.a
I use all this 4 lines for every lib I need. In this case my lib is named "libOne.a" and my paths structure is something like this: ( so you can understand it better)
workspace (folder) |-----QtProject (folder) | |-Myproject (folder) | |- MyProject.exe // so from here u have to go up 2 steps (that's why I have "$$PWD/../../" |-----LibOne (Folder) | |-Release (folder) | | |- libOne.a (The file I want) | |- Debug (folder) ...
Hope it helps you.
@roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix
lib
when you're linking a library namedlib<xxx>.so
(or.a
) -
@roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix
lib
when you're linking a library namedlib<xxx>.so
(or.a
)@tarod.net neither do I hehe I'm new on this but I had to work on a fedora with Qt and as this worked fine for me, I thought it could help @houmingc so I posted an example of my case. Even if you don't need to put the "lib" it doesn't mean that putting it its wrong and as shown with my example, it works too :) In my case if its possible I prefer to put the entire name or path so its more clear to understand.
Anyway its always nice to learn new things so thanks for the info and the link! :) I'll keep it in mind the next time
-
@tarod.net neither do I hehe I'm new on this but I had to work on a fedora with Qt and as this worked fine for me, I thought it could help @houmingc so I posted an example of my case. Even if you don't need to put the "lib" it doesn't mean that putting it its wrong and as shown with my example, it works too :) In my case if its possible I prefer to put the entire name or path so its more clear to understand.
Anyway its always nice to learn new things so thanks for the info and the link! :) I'll keep it in mind the next time
@roseicollis Great! Thank you! :)
-
@roseicollis Great! Thank you! :)
-
@roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix
lib
when you're linking a library namedlib<xxx>.so
(or.a
)