Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2006
Detecting static vs. shared in .pro file


Message 1 in thread

I've come up with a dirty hack to detect at qmake if the Qt library is 
static or shared, but I'm sure there is a better way:

  exists( $$QMAKE_LIBDIR_QT/libQtGui.a ) {
      # This is a static Qt
  } else {
      # This is a shared Qt
  }

Is there a more straightforward way?

--Dave

--
 [ signature omitted ] 

Message 2 in thread

Dave Smith wrote:

> I've come up with a dirty hack to detect at qmake if the Qt library is
> static or shared, but I'm sure there is a better way:
> 
>   exists( $$QMAKE_LIBDIR_QT/libQtGui.a ) {
>       # This is a static Qt
>   } else {
>       # This is a shared Qt
>   }
> 
> Is there a more straightforward way?

Perhaps you could use the CONFIG() function:

http://doc.trolltech.com/4.2/qmake-function-reference.html#config-config

This allows you to test for certain values in the CONFIG variable:

http://doc.trolltech.com/4.2/qmake-variable-reference.html#config

-- 
 [ signature omitted ] 

Message 3 in thread

Von: David Boddie <dboddie@xxxxxxxxxxxxx>
> Dave Smith wrote:
> 
> > I've come up with a dirty hack to detect at qmake if the Qt library is
> > static or shared, but I'm sure there is a better way:
> > 
> >   exists( $$QMAKE_LIBDIR_QT/libQtGui.a ) {
> >       # This is a static Qt
> >   } else {
> >       # This is a shared Qt
> >   }
> > 
> > Is there a more straightforward way?
> 
> Perhaps you could use the CONFIG() function:
> 
> http://doc.trolltech.com/4.2/qmake-function-reference.html#config-config
> 
> This allows you to test for certain values in the CONFIG variable:
> 
> http://doc.trolltech.com/4.2/qmake-variable-reference.html#config
> 
I don't think this will help here. He wants to know the library type when he's compiling his own program. This is not possible (in an easy way) atm - the only way is to parse the .prl - file.

With the above solution you'll fail on windows.

Christian
-- 
 [ signature omitted ] 

Message 4 in thread

Christian Ehrlicher wrote:
>>> I've come up with a dirty hack to detect at qmake if the Qt library is
>>> static or shared, but I'm sure there is a better way:
>>>
>>>   exists( $$QMAKE_LIBDIR_QT/libQtGui.a ) {
>>>       # This is a static Qt
>>>   } else {
>>>       # This is a shared Qt
>>>   }
>>>
>>> Is there a more straightforward way?
>>>       
>
> With the above solution you'll fail on windows.
>   

Fortunately for me, on Windows I always use the shared library. :) But I 
guess I could check for the QtGui.lib file...

--Dave

--
 [ signature omitted ] 

Message 5 in thread

Von: Dave Smith <dave@xxxxxxxxxxxxxxx>
> Christian Ehrlicher wrote:
> >>> I've come up with a dirty hack to detect at qmake if the Qt library is
> >>> static or shared, but I'm sure there is a better way:
> >>>
> >>>   exists( $$QMAKE_LIBDIR_QT/libQtGui.a ) {
> >>>       # This is a static Qt
> >>>   } else {
> >>>       # This is a shared Qt
> >>>   }
> >>>
> >>> Is there a more straightforward way?
> >>>       
> >
> > With the above solution you'll fail on windows.
> >   
> 
> Fortunately for me, on Windows I always use the shared library. :) But I 
> guess I could check for the QtGui.lib file...
> 
QtGui4(d).lib is there in static and shared mode (it's either the needed static import lib or the complete static lib). So you should check for QtGui4(d).dll instead.

Christian

-- 
 [ signature omitted ] 

Message 6 in thread

Dave Smith schrieb:
> Christian Ehrlicher wrote:
>>> ...
>> With the above solution you'll fail on windows.
>>   
> 
> Fortunately for me, on Windows I always use the shared library. :) But I
> guess I could check for the QtGui.lib file...

Remember that you _always_ have a *.lib file on Windows. Even if the
actual library is dynamic (*.dll).

So merely checking for the existence of a *.lib file is _not_ enough as
to determine whether the library is static or dynamic - in case you
meant this.

Cheers, Oliver

--
 [ signature omitted ] 

Message 7 in thread

Christian Ehrlicher wrote:

> I don't think this will help here. He wants to know the library type when
> he's compiling his own program. This is not possible (in an easy way) atm
> - the only way is to parse the .prl - file.

That's what I thought when I started to write a reply, and I made a static
build of Qt 4.2 to check this. Of course, it appears to work inside the Qt
build directory, and that's what confused me.

There's no need to parse the .prl file if you can include it. The following
lines should include the contents of the libQtGui.prl file and allow you to
test for the presence of "shared" 

TEMP = $$[QT_INSTALL_LIBS] libQtGui.prl
include($$join(TEMP, "/"))

contains(QMAKE_PRL_CONFIG, shared) {
    message(Shared Qt)
} else {
    message(Static Qt)
}

There may well be a cleaner way of doing this.

-- 
 [ signature omitted ]