PDA

View Full Version : Linking a .a and .dll library to Qt project



ehnuh
11th October 2012, 07:47
Hi, I am currently developing a qt sub directory project. This is the structure:

Root Project:
Root.pro
Subdir Project:
Subdirapp.pro - TEMPLATE = app
Subdirlib1.pro - TEMPLATE = lib
Subdirlib2.pro - TEMPLATE = lib
Subdirlib3.pro - TEMPLATE = lib
Subdirlib4.pro - TEMPLATE = lib

First, I would like to ask how can I create a shared library for the subdirectory projects(Subdirlib1.pro,Subdirlib2.pro,Subdirlib3. pro and Subdirlib4.pro).
Second, I would like to ask how can I link those subdir projects using this shared library allowing me to use UI and functions of every

Upon building the projects. ".a" and ".dll" were generated.
I am currently working on MINGW build configuration.

I really need your help guys! Please.
Thanks in advance

-ehnuh-

ChrisW67
11th October 2012, 08:19
If you have DLL generated for each library sub project then you already have shared libraries.

In the app project pro file you add the libraries/library paths you wish to link against to the LIBS variable and, if necessary, add an include search directory to INCLUDEPATH.

ehnuh
11th October 2012, 09:23
Hi sir, currently I have tried this method:


..I am currently using mingw compiler, so the library file format generated is a '.a' and '.dll' format.

I added the library using 'add internal library'. This generated the code in my .pro file.

unix:!symbian|win32: LIBS += -L$$OUT_PWD/../../../BiTCommon/Template/Project/ -lTemplate

INCLUDEPATH += $$PWD/../../../BiTCommon/Template/Include
DEPENDPATH += $$PWD/../../../BiTCommon/Template/Include

..upon building the project, it gives me this error.
'cannot find -lTemplate'

..Next I tried to change the -lTemplate to -aTemplate since the library generated was in a '.a' format. Upon building there were no errors but when I instantiated the class it gave me this error.


error: undefined reference to `_imp___ZN19CTemplateMainWindowC1EP7QWidget'


..any inputs would really be helpful. To cut the long story short, I was previously compiling in msvc and it generated .lib files and I just link it to my project. Now that it is in mingw, it generates a different file format.

ChrisW67
11th October 2012, 09:32
You are telling Qt that there is a library called "libTemplate.a" in a folder "$$OUT_PWD/../../../BiTCommon/Template/Project/" (wherever that resolves to) or elsewhere on the standard path. I guess it is not there.

ehnuh
11th October 2012, 10:01
Hi sir thanks for the reply! When 'add an internal library' option is chosen in Qt, it detects the .pro files in the subdirs project. When 'add an external library' is chosen, it only detects .lib files. It does not detect the .a files.

Added after 18 minutes:

Hi sir! Thanks for the input! Just realized that I was calling the library from the wrong path. I had to manually edit the path to the correct library path. I instantiated the class and the UI showed! Thanks!

Karan
21st October 2012, 16:55
Hey,

i need to link qwt library to my program:

i changed the pro file the following way:

CONFIG += qwt

#-the port com library :
INCLUDEPATH += C:\Qt\qextserialport-1.2win-alpha\
LIBS += C:\Qt\qextserialport-1.2win-alpha\build\libqextserialportd.a

#-the graphic library :
INCLUDEPATH += C:\QtSDK\qwt-6.0.0\src\
LIBS += C:\QtSDK\qwt-6.0.0\lib\libqwtd.a

but it says libqwtd.a is not a directory
and libqextserialportd.a is not a directory.

The folder also has .dll files but the same happens...

Pls suggest what should i do???

mak187
29th March 2013, 03:07
Has anyone answered this anywhere?
I have a similar issue on windows. I get both mylib.dll and libmylib.a created. Nothing you do will allow the classes/methods be used in another project.
I have this in my exe pro file:
INCLUDEPATH += /cpp/qt/mylib
LIBS += -L/cpp/qt/mylib/debug -lmylib

This DOES NOT WORK...get undefined references to all the used methods.
This DOES WORK under linux without issue.

ChrisW67
29th March 2013, 05:49
Firstly, where do you suppose the path "/cpp/qt/mylib/" is on a Windows machine? Without the drive specified this may not be where you think it is.

Assuming the library file itself is actually found by the linker: if your dynamic library does not export the symbols you wish to use then they will not be visible. GCC on LInux exports by default, on Windows it does not. See Using Symbols from Shared Libraries in the friendly manual.

Next time you might try providing more information about the actual problem, like the relevant output from the linker, rather than just shouting that it does not work.