PDA

View Full Version : How to create a library and use it in Qt 4.7.4 and Creator 2.2.0



_perza
30th August 2011, 13:03
I do not seem to find uptodate instructions about the subject matter, so here is the question:

I am using Creator in Windows and targeting to Qt simulator (as the first target, later also other platforms).

When I create a new C++ library project with Creator wizard and build it, it seems to create a "MyLib.a" named static library in the target folder. So far so good.

However, how to use this library?

I have added this kind of lines into application .pro file

LIBS += c:/lib/MyLib.a
INCLUDEPATH += c:/source/MyLib

and also included the header file in the application code file.

The application builds OK, but trying to run it produces:

"exited with code -1073741515"

error immediately when started.

What am I missing?

br, _perza

srazi
30th August 2011, 13:22
in this way:


LIBS += -lc:/lib/MyLib

_perza
31st August 2011, 08:33
What do the LIBS options -L and -l actually do? Are there some docs on these somewhere?

Somehow the original lib and a small test app started working in simulator, but when trying to build the exactly same app for Symbian device I get the following error message:

:-1: error: Recipe linkandpostlink failed with exit code 1.

.... with tens of lines unrelated compiler messages, and finally...

undefined reference to `MyLib::MyLib()

indicating that compiler can not find the library functions. I have build both the library and the application to the same Symbian^3 target, as far as I understand.

Using libraries in this environment feels ridiculously complicated :mad: Any ideas what might be wrong?

br, _perza

Added after 5 minutes:

"... it seems to create a "libMyLib.a" named static library in the target folder..."

"LIBS += c:/lib/libMyLib.a"

I noticed that I had forgotten 'lib' -prefix from couple of places in original post; they are correct in actual files though, so that does not explain the problems.

br, _perza

wysota
31st August 2011, 08:34
What do the LIBS options -L and -l actually do? Are there some docs on these somewhere?
Sure there are. -L tells the compiler where to look for libraries and -l tells it which libraries to link against. Those are standard gcc switches.


Somehow the original lib and a small test app started working in simulator, but when trying to build the exactly same app for Symbian device I get the following error message:

:-1: error: Recipe linkandpostlink failed with exit code 1.

.... with tens of lines unrelated compiler messages, and finally...

undefined reference to `MyLib::MyLib()

indicating that compiler can not find the library functions. I have build both the library and the application to the same Symbian^3 target, as far as I understand.
Hard to say what you did or did not do, especially if you are not sure yourself what you did :) Please provide more info and post your .pro files.


Using libraries in this environment feels ridiculously complicated :mad:
It's not complicated. It just requires you to do some things conciously.

Any ideas what might be wrong?
You are either not building the libraries properly or didn't provide proper information to the linker to find your library.

_perza
31st August 2011, 09:39
Thanks for the reply. Your advice was good, so I started making minimal lib & app that I could share here.

However, when I tried to build the minimal MyLib static library for Symbian device, I did not find the libMyLib.a file anywhere. Building it for simulator creates a libMyLib.a file, but device build does not seem to create anything! No wonder the earlier tests failed.

Interesting enough, there is a MyLib.lib file deep in the Qt SDK folder (C:\QtSDK\Symbian\SDKs\Symbian3Qt473\epoc32\releas e\armv5\urel).

Now, what the heck is this about?

wysota
31st August 2011, 09:43
I wouldn't expect to receive libMyLib.a because probably your Symbian build is not done by gcc but rather some other compiler so the naming scheme will be different.

_perza
31st August 2011, 10:19
Interesting note. I followed that and found this from the 4.7 documentation

"GCCE (Symbian)
GCCE cannot be used to compile Qt libaries for the Symbian platform, but GCCE is supported when compiling Qt applications for the Symbian platform."

Thus I can not make symbian libs with standard Qt 4.7 compiler??? Is this correct, and how to do it then?

wysota
31st August 2011, 10:43
I think it is more that "Qt libs" (as in QtCore, QtGui, etc.) can't be built using GCCE and not your own libs. However I have no experience with Symbian so it is just my guess. I think you should verify that on some Symbian forum.

_perza
31st August 2011, 10:49
OK... now I suddenly got it working as it should. The problem was the wrong combination of compiler options (e.g.):

LIBS += -llibMyLib

should have been

LIBS += -lMyLib

so simple ...

BTW, srazi, credits to you for perfect answer in th first place :)

wysota
31st August 2011, 10:54
Correct me if I'm wrong but this will make your app use a shared library and not a static one, no?

_perza
2nd September 2011, 10:35
I am trying to make a minimal app that uses both static and a dynamic library.

I am now quite close (I hope), but there is a mysterious

"Could not install from package C:\Data\MyApp.sis on device: General OS-related error"

error every time I want to run it in the device. I have no clue what might cause this.