how to statically link .a to qt (solved)
-
wrote on 11 Jun 2015, 09:53 last edited by houmingc
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 -
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 libQLogLibwrote on 11 Jun 2015, 11:54 last edited by tarod.net 6 Nov 2015, 11:55@houmingc You don't need to write "lib". I mean, it's enough to write the next line:
LIBS += -lQLogLib
If the compiler doesn't find the the lib, you'll need to add the path:
LIBS += -L<path_to_lib> -lQLogLib
-
wrote on 12 Jun 2015, 09:38 last edited by
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
-
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
wrote on 12 Jun 2015, 10:03 last edited by@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.
-
wrote on 13 Jun 2015, 02:12 last edited by houmingc
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
wrote on 14 Jun 2015, 03:15 last edited by houmingcSir, 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
-
wrote on 15 Jun 2015, 02:31 last edited by
I try another method, documented below:-
Add Library <Right-clip Project file>
Select External library, In Library File, select libQLogLib.a
Clean
run qmake
build
error: cannot find -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
wrote on 17 Jun 2015, 11:17 last edited by@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
-
wrote on 17 Jun 2015, 14:53 last edited by roseicollis
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.
wrote on 18 Jun 2015, 06:12 last edited by@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
)wrote on 18 Jun 2015, 07:14 last edited by@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
wrote on 18 Jun 2015, 08:40 last edited by@roseicollis Great! Thank you! :)
-
@roseicollis Great! Thank you! :)
wrote on 26 Jun 2015, 05:51 last edited byThanks you. it worked
-
@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
)wrote on 14 Jul 2015, 08:57 last edited bySomeone direct me to insert the line below and it solved my problem.
Can someone explain what this line of code do in Qt project?unix|win32: LIBS +=-lrt
-
@houmingc this line means: on either unix or win32 link to the rt library
-
wrote on 15 Jul 2015, 01:51 last edited by houmingc
Thanks.
Where is rt library in ubuntu?
How to check if rt library is install in ubuntu and install it? i try " locate librt "
Why is it not linked automatically?