Unsolved Building .pro as library - suggestions ?
-
When I build a project as TEMPLATE=lib I no longer have an option to "run" such project.
I can add then build library to my main subproject and keep editing and rebuilding it as necessary.What would be a reasonable way to be able to test the subproject as before , as "app"?
Someting likes
#ifdef app
run project as app
#else
use project as lib
#endif -
@AnneRanch What about making a project dedicated for testing your library ? So things are kept separated and you can also test importing the library into a "root" project.
-
An app is a program that has a
main()
function. A library is just a bunch of functions exported to be used by another project. Switching between them in a single project is not something that is usually done. What would happen to themain()
function if you treat it as a library? What if that main contains important functionality e.g. in case of Qt apps starts an event loop? You can't just skip that if you treat it as a library, or, if you do skip it, you would have to duplicate the same functionality in the actual app. It would be a big waste.The scenario you described is a common thing when you talk about testing. Basically you have 3 projects:
- A library with all the functionality.
- The main application which links that library. It has a
main()
function that does the basic setup and runs that library code. - A test framework application that links to the library and runs tests on individual functions from it.
In such setup you don't have to switch anything or do any extra work. You just run either the main app or the testing app. Both use the same library.
-
I think that is a solution. That way I can keep editing the source ans still run the "library" a stand alone project -
as long as I keep the "inlcude(s) " happy . .
I'll give a go.