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

Qt-interest Archive, May 2007
how to build a project contaiing subfolders?


Message 1 in thread

I just started my first Qt project on windows.  The directory layout of my
subject is like this:

-MyProject

----Gui

----Main.cpp

 

I made this directory layout because it's simple enough and allows me to
have some experiences with building a project with subdirectories.

 

The pro file in top level looks like this:

TEMPLATE=subdirs

SUBDIRS=Gui

SOURCES=Main.cpp

CONFIG=debug qt

 

The pro file in Gui subdir is named Gui.pro and looks like this:

SOURCES=mainWindow.cpp

HEADERS=mainWindow.h

 

I used 'qmake MyProject.pro' to generate the makefiles, this step was ok.

But 'make' gave me the following error:

c:\Qt\4.2.3\lib/libqtmaind.a(qtmain_win.o)(.text+0x30b): In function
`WinMain':

C:/Qt/4.2.3/src/winmain/qtmain_win.cpp:105: undefined reference to
`qMain(int, char**)'

 

Could anyone help me out?  Thanks 

 

 


Message 2 in thread

On 11.05.07 12:21:23, Yifei Li wrote:
> I just started my first Qt project on windows.  The directory layout of my
> subject is like this:
> 
> -MyProject
> 
> ----Gui
> 
> ----Main.cpp

Thats not possible with qmake. A directory can either contain subdirs or
source files, but not both. (well it can, but a .pro file can only build
from sources or go into subdirs).

> The pro file in top level looks like this:
> 
> TEMPLATE=subdirs
> SUBDIRS=Gui
> SOURCES=Main.cpp
> CONFIG=debug qt

See above, that won't work.

> The pro file in Gui subdir is named Gui.pro and looks like this:
> SOURCES=mainWindow.cpp
> HEADERS=mainWindow.h

This .pro file misses some information about wether it should build an
executable or library.

> But 'make' gave me the following error:
> 
> c:\Qt\4.2.3\lib/libqtmaind.a(qtmain_win.o)(.text+0x30b): In function
> `WinMain':

Because by default the Makefile will try to build a executable in the
Gui subdir, but you don't provide a main() function.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

Thanks a lot, Andreas.

But if I want to build a single executable from several subdirs, how can I 
do that?

You mentioned  "This .pro file misses some information about wether it 
should build an
 executable or library", do you mean that I should put 'TEMPLATE=app' in the 
pro file in only one subdir and treat other subdirs as libraries ?

Yifei

Do
----- Original Message ----- 
From: "Andreas Pakulat" <apaku@xxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Friday, May 11, 2007 1:12 PM
Subject: Re: how to build a project contaiing subfolders?


> On 11.05.07 12:21:23, Yifei Li wrote:
>> I just started my first Qt project on windows.  The directory layout of 
>> my
>> subject is like this:
>>
>> -MyProject
>>
>> ----Gui
>>
>> ----Main.cpp
>
> Thats not possible with qmake. A directory can either contain subdirs or
> source files, but not both. (well it can, but a .pro file can only build
> from sources or go into subdirs).
>
>> The pro file in top level looks like this:
>>
>> TEMPLATE=subdirs
>> SUBDIRS=Gui
>> SOURCES=Main.cpp
>> CONFIG=debug qt
>
> See above, that won't work.
>
>> The pro file in Gui subdir is named Gui.pro and looks like this:
>> SOURCES=mainWindow.cpp
>> HEADERS=mainWindow.h
>
> This .pro file misses some information about wether it should build an
> executable or library.
>
>> But 'make' gave me the following error:
>>
>> c:\Qt\4.2.3\lib/libqtmaind.a(qtmain_win.o)(.text+0x30b): In function
>> `WinMain':
>
> Because by default the Makefile will try to build a executable in the
> Gui subdir, but you don't provide a main() function.
>
> Andreas
>
> -- 
> You will be called upon to help a friend in trouble.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> 

--
 [ signature omitted ] 

Message 4 in thread

On 11.05.07 13:26:44, Yifei Li wrote:
> Thanks a lot, Andreas.

I don't need a copy of the mail, its enough to send your reply to the
list, thanks.

> But if I want to build a single executable from several subdirs, how can I do 
> that?

There are two ways:

a) use libraries
b) only build in 1 subdir and add all source files from othre dirs
relatively in that

a) can be done with either shared or static libs

b) would look like this:

Gui/foobar.cpp
Gui/foobar.h
Forms/barfoo.ui
App/main.cpp

and App/app.pro:

TEMPLATE=app
SOURCES = main.cpp ../Gui/foobar.cpp
HEADERS = ../Gui/foobar.h
FORMS = ../Forms/barfoo.ui

> You mentioned  "This .pro file misses some information about wether it should 
> build an
> executable or library", do you mean that I should put 'TEMPLATE=app' in the pro 
> file in only one subdir and treat other subdirs as libraries ?

Yeap, either that or the above. The thing to remember is moving the
main.cpp into the subdir that has template=app (or reference it from the
.pro file that builds the app).

Andreas

-- 
 [ signature omitted ] 

Message 5 in thread

On 5/11/07, Yifei Li <yifli@xxxxxxx> wrote:
> Thanks a lot, Andreas.
>
> But if I want to build a single executable from several subdirs, how can I
> do that?
>

If the project consists of several libraries and an executable in
subdirs.  Start with individual project files for each subdir then
make one "top level" subdir project like this:
----------
TEMPLATE = subdirs
# ordered has many systems build in the given order
CONFIG += ordered
SUBDIRS = \
  path\FirstLibrary \
  path\SecondLibrary \
  path \Executable Project
----------

If you have just one mammoth executable spread across multiple subdirs
either make one project file at the top of the directory structure
that give HEADERS and SOURCES for each file using relative paths.  Or
create several .pri files in each subdir that add HEADERS and SOURCES
and then use the "include(filename)" command to include them in the
top level folder.

--Robert
> You mentioned  "This .pro file misses some information about wether it
> should build an
>  executable or library", do you mean that I should put 'TEMPLATE=app' in the
> pro file in only one subdir and treat other subdirs as libraries ?
>
> Yifei
>
> Do
> ----- Original Message -----
> From: "Andreas Pakulat" <apaku@xxxxxx>
> To: <qt-interest@xxxxxxxxxxxxx>
> Sent: Friday, May 11, 2007 1:12 PM
> Subject: Re: how to build a project contaiing subfolders?
>
>
> > On 11.05.07 12:21:23, Yifei Li wrote:
> >> I just started my first Qt project on windows.  The directory layout of
> >> my
> >> subject is like this:
> >>
> >> -MyProject
> >>
> >> ----Gui
> >>
> >> ----Main.cpp
> >
> > Thats not possible with qmake. A directory can either contain subdirs or
> > source files, but not both. (well it can, but a .pro file can only build
> > from sources or go into subdirs).
> >
> >> The pro file in top level looks like this:
> >>
> >> TEMPLATE=subdirs
> >> SUBDIRS=Gui
> >> SOURCES=Main.cpp
> >> CONFIG=debug qt
> >
> > See above, that won't work.
> >
> >> The pro file in Gui subdir is named Gui.pro and looks like this:
> >> SOURCES=mainWindow.cpp
> >> HEADERS=mainWindow.h
> >
> > This .pro file misses some information about wether it should build an
> > executable or library.
> >
> >> But 'make' gave me the following error:
> >>
> >> c:\Qt\4.2.3\lib/libqtmaind.a(qtmain_win.o)(.text+0x30b): In function
> >> `WinMain':
> >
> > Because by default the Makefile will try to build a executable in the
> > Gui subdir, but you don't provide a main() function.
> >
> > Andreas
> >
> > --
> > You will be called upon to help a friend in trouble.
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ]