PDA

View Full Version : qmake and library version handling



viridis
5th March 2009, 12:04
Hi,

I've the following .pro file to compile a library called "mylib" :



TEMPLATE = lib
VERSION = 0.1
TARGET = mylib
...


When compiling under windows with QtCreator (mingw), it generates a file named "mylib0.dll" (and a "mylib0.a"). Now, if I compile under linux with g++, I got "mylib.so -> mylib.so.0 -> mylib.so.0.1-> mylib.so.0.1.0".

When I tried to use the library from another .pro files, I do:


TEMPLATE = app
TARGET = test
LIBS += -L ../mylib -lmylib
INCLUDEPATH += ../mylib/include
...


It works under linux, as the linker search for a "mylib.so" file, but It is not working under windows. If I change "-lmylib" with "-lmylib0", it works under windows but not under linux (as the file is called "mylib.so.0".

How can I handle this ? I'm trying to find a solution which avoid specifying as much as possible scopes. This is because I want to support a lot of platform and do not want, in each of my pro files, making win32 {..}, unix {...}, mingw {...} etc just for the linking purpose.

Regards,

talk2amulya
5th March 2009, 15:57
since you are using versioning, file names are coming out to be different. now, either u add both -lmylib and -lmylib0 in -LIBS or u can avoid using the version tag..otherwise u'll hv to stick to platform-specific entries.

fullmetalcoder
5th March 2009, 16:38
Versioning *should* not be an issue. I have used it in several projects making use of shared libraries and it worked just fine without requiring any trick...

AFAIK the following will always work, no matter the versioning :

LIBS += -lmylib

Because the linker (is supposed to) take care of adding prefix/suffix/versioning to match the platform specific conventions when it searches for a matching shared lib.

The only issue I can see in your pro is the space in the LIBS assignement. It ought to be written like that :

LIBS += -L../mylib

viridis
6th March 2009, 09:27
since you are using versioning, file names are coming out to be different. now, either u add both -lmylib and -lmylib0 in -LIBS or u can avoid using the version tag..otherwise u'll hv to stick to platform-specific entries.

Specifying both -lmylib and -l mylib0 does not work (which is correct since the linker will try to open both libraries but only one exists!)



Because the linker (is supposed to) take care of adding prefix/suffix/versioning to match the platform specific conventions when it searches for a matching shared lib.


Apparently, this is not the case on windows. I've tried with QtCreator/MinGW and -lmylib does not work. I've tried to import my .pro file into VisualStudio using the QtVSIntegration, and it does not work too. I've even tried with nmake inside a console without success.

PS: I wrote "LIBS += -L../mylib" in my .pro file, without spaces. I've introduced the error while writing the post :)