Solved Regarding the static library loading fails
-
Hi,
I have built static library and the pro file info is.
https://postimg.org/image/el9nd8lx9/
I have created another application , where i have included the header file and library file to the application.
The link is below.
https://postimg.org/image/v2qprwpi5/
And when i use QLibrary to load in main file
https://postimg.org/image/fl11y9shz/
I am getting error cannot load the library, Invalid ELF header.
Where am i doing wrong,
guidance is required?.Thanks,
-
Hi
First thing. a static library is linked into the application.
So its not possible to load later using QLibrary.Via the LIBS += in pro file you
tell it to look for "staticlib " in a sub folder to the project called Libraries.Is that correct?
You can click the pro file, then right click the edit area and use the "add library" dialog
then compare paths.https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
http://stackoverflow.com/questions/1361229/using-a-static-library-in-qt-creator
The add lib dialog
http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html -
correct me if i my understanding is wrong.
If we include the libraries and header files created from one project and adding to the .pro file of another project, that means we are adding static library, linking to the application for the usage.First thing. a static library is linked into the application.
So its not possible to load later using QLibrary.Via the LIBS += in pro file you
as u mentioned @mrjj that means the library got created successfully and i have linked to my another application, so loading later using QLibrary is of no use.
Is my understanding correct?.So only i am getting the error as cannot load library invalid ELF header,
But still widget is showing.
The link is below
-
A static lib must be linked into the application so QLibrary cannot be used.
(it will report error)- But still widget is showing.
so WidgetApplication comes from the static lib?
Normally it complains if cant link what you ask of it so it sounds like you are in fact using the static lib but only u can tell :)
-
Yes i have used static lib , inherited the class from QWidget. So i am calling the class name as WidgetApplication.
so .pro file of WidgetApplication. Is below
-
Ok so it seems to use the lib ?
So it was working :) -
Hmmmm
came to know when we want to allocate the memory using the libraries created , then we need to go for using the class QLibrary.
If we use static libraries linked to out application, memory will be allocated.Thanks,
-
@Pradeep-Kumar
Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
with shared libs. So if you need to only have it active is needed - than dynamic library is better.
Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
always compiled into the app and in that way takes extra memory. -
@mrjj said in Regarding the static library loading fails:
@Pradeep-Kumar
Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
with shared libs. So if you need to only have it active ia needed - than dynamic library is better.
Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
always compiled into the app and in that way takes extra memory.Just explained nicely and ellaborated my previous post answer.
with the static lib, executable size also increases.Got it man.
-
@Pradeep-Kumar
executable size also increases.Indeed it does. A plain empty default project compiled with static Qt is around 15 MB as the Qt dlls are compiled into it.
For debug builds, it can get insane big. exe > 200 MB! -
Then if i have to use QLibrary then shared libraries comes into picture, and then only i can use it.
Hmmmmmmm:))))))))))
-
@Pradeep-Kumar
If the lib is a Qt lib and the app that will use it - is a Qt app, I highly suggest you have a look at Qt plugins as
it is a smart(er?) way to use shared libs.http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html
The same way Creator uses its plugins , you can use for your app and libs.
it uses a interface design and its easier to handle than raw loading as it helps exporting QWidgets with more in
a nice manner. It takes a little to get up and running but after that its pretty easy to use.http://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html
-
Hi,
I got the output and it is working in multiple devices.
Thanks for the help and guidance provided.So marking as Solved.
Thanks,