PDA

View Full Version : Best approach to keep a set of common functions



czdcriacoes
10th October 2012, 16:37
Hi all,

I'd like to know the best approach for keeping one or more sources containing functions in a way I can reuse them easily in several projects. Or, in other words, I'd like to create a personal library of common functionalities (custom math functions, for example).
And, as a newbie, how I follow that approach in Qt Creator (menu options etc.)?

P.S.:
if answer is ".lib's", I've tried to create .lib's at %CPPLIBS% directory but I failed in each step :-( ...
how do I create .lib in Qt Creator?

Zlatomir
10th October 2012, 17:30
To create a library with Creator you do this: New project -> Other Project -> C++ Library and in the dialog that appears after you can configure if you create a shared library or a statically linked one (from what i understand this is what you want).

//Another way that may fit your needs is to create a header only library.

czdcriacoes
10th October 2012, 23:57
ok, I'll try both of them.

And how do I use each of them in the client project? I'm using #include but it doesn't work. The "Add library..." option always look for a .lib, which I can't find it anywhere :-(

Zlatomir
11th October 2012, 00:37
To reuse a library in a project you use the qmake's: INCLUDEPATH (http://doc.qt.digia.com/4.7-snapshot/qmake-variable-reference.html#includepath) and (if necessary) LIBS (http://doc.qt.digia.com/4.7-snapshot/qmake-variable-reference.html#libs) in the project file (.pro extension).

czdcriacoes
11th October 2012, 03:56
error message:

undefined reference to <myfunction>
:(