Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build a static library and executable with Qt?

Tags:

c++

qt

qmake

To simplify the situation, lets say that there are 2 files: core.cpp and main.cpp.

core.cpp contains the functionality of the program and main.cpp contains the basic main() implementation.

I want Qt (using qmake and the .pro files) to

  • first build core.a and then
  • use that and main.cpp to build main.exe.

How do I set this up in the qmake file?

like image 711
chacham15 Avatar asked Apr 05 '12 19:04

chacham15


People also ask

Is Qt a library or framework?

Qt is a framework, not a library. This isn't a hard-and-fast distinction enforced by the programming language, rather, it describes how the code is designed and intended to be used: A library is someone else's code that is used by your code.


1 Answers

Filesystem layout:

MyProject |_ myproject.pro |_ core    |_ core.cpp    |_ core.h    |_ core.pro |_ app    |_ main.cpp    |_ app.pro 

myproject.pro:

TEMPLATE = subdirs CONFIG += ordered SUBDIRS = core \           app app.depends = core 

core.pro:

TEMPLATE = lib CONFIG += staticlib HEADERS = core.h SOURCES = core.cpp 

app.pro:

TEMPLATE = app SOURCES = main.cpp LIBS += -L../core -lcore TARGET = ../app-exe # move executable one dire up 
like image 71
Masci Avatar answered Oct 17 '22 22:10

Masci