13

I have a shared library (with no QT dependency) [library B] that links to another shared library (with no QT dependence as well) [library A].

I am using Qmake and QT Creator 1.3. The problem is that when I build library B and run ldd on the executable, it is being linked to QtCore and QtGui, both of which are pulling in lots of unrequired files, resulting in an executable that is taking long to load, and has unwanted dependencies.

I have tried just about everything to stop qmake from linking these libraries to library B.

A snippet of my project file for library B is shown below:

TEMPLATE = lib
LIBS += -L../datelib/bin -ldatelib_release

QT -= gui core
LIBS   -= -lQtGui -lQtCore
CONFIG += dll
CONFIG += debug_and_release

CONFIG(debug, debug|release) {
TARGET =targetnameD
}else {
TARGET = targetname
}

I am using QtCreator 3 on Ubuntu 9.10

QT is version 4.5.2

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stick it to THE MAN
  • 5,621
  • 17
  • 77
  • 93
  • Which version of Qt? I tried with 4.6.1 and with Qt -= core gui the Makefile created by qmake did not include the Qt DLLs, removing this line included them in the Makefile. – David Dibben Feb 19 '10 at 14:34

5 Answers5

14

Put CONFIG -= qt in your .pro file.

rohanpm
  • 4,264
  • 17
  • 16
  • 1
    It works here. This is the method used for the projects in the Qt source tree which don't link against Qt. In general, it works. See `src/winmain/winmain.pro` in the Qt source tree for an example. Can you double-check: (1) you really ran qmake again and rebuilt everything (do a completely clean build after running qmake). (2) None of the libraries you link against are themselves linking against libQtCore or libQtGui (e.g. `datelib_release` must not link against Qt). – rohanpm Feb 21 '10 at 01:32
3

You can try with

CONFIG += dll
QT     -= gui core
LIBS   -= -lQtGui -lQtCore
gregseth
  • 12,952
  • 15
  • 63
  • 96
  • I have marked your answer up, because it atleast gave me the confidence to look more closely at what was actually being built - and I then realised that (unlike my other projects that were set to release configuration by default), this project was set to default - infact there was no other configuration shown by QtCreator even though the (configuration section of the) .pro file syntax is identical to the other projects. Do you know what could be causing this? – Stick it to THE MAN Feb 19 '10 at 14:54
  • Look at and/or delete the yourporjectname.pro.user file. – Mihai Limbășan Feb 19 '10 at 15:09
  • @Mihai: this was the first thing I did (before posting my question), it made no difference. – Stick it to THE MAN Feb 19 '10 at 15:23
  • Ah, sorry. It was a shot in the dark - many people don't realize that the *user files can also influence the resulting build artifacts. – Mihai Limbășan Feb 19 '10 at 19:59
  • Is the LIBS line really neccessary? I mean if I don't need the gui libs, QT -= gui is enough to disable -lQtGui. – maxschlepzig Jan 06 '11 at 16:47
2

For apps, you do it like this:

TEMPLATE = app
CONFIG = console

More info here: qmake common projects

Ben
  • 429
  • 4
  • 6
1

I had similar problem. What I did was to create new library project with out qtcore and qtgui. Removed all unnecessary files that was created by wizard. Added my files to project folder and modified the *.pro file. It started to work correctly.

It was some problem with QtCreator, it not read correctly .pro file generating .pro.user, witch QtCreator use to build, and wizard generate correct .pro.user file.

I did this with Qt 4.7

Wish this help.

firescreamer
  • 620
  • 8
  • 20
0

As far as I know, Qt creator doesn't take the .pro configurations into consideration if you don't have them set up separately from the IDE.

You should go to the project's settings, clone the debug configuration, rename it release, set the QMake build configuration to release(!) and change other settings as you see fit. Then you can pick which configuration to build from the IDE.

P.S: Try using Qt Creator 1.3.1 as it fixes a lot of bugs and brings interesting new features.

rpg
  • 7,746
  • 3
  • 38
  • 43
  • Hmm, it appears to have been a 1.2.1 bug. After I installed v3, the problem disappeared ... But just so I know for the future, when I want to create my own configuration, could you please outline the steps required in "cloning" an existing configuration to create a new one? – Stick it to THE MAN Feb 19 '10 at 15:39
  • Go to Projects > Build Settings > Add > Clone selected. Then select the new configuration (e.g Release) and expand the QMake build step. Set the QMake build configuration to release and you're done. – rpg Feb 22 '10 at 10:58