I wanted to build an application that both runs on Gtk 2 and Gtk 3 environments. What are my options?
I am using C++ with cmake
on a linux machine.
- Have two separate projects?
Of course that's an option.
- Have two separate build steps?
That, too, but the key objective there is to produce two different binaries (not necessarily both standalone executables, though, see below).
- Can a single executable be built so that it is able to run on both environments?
Yes, but doing so is not straightforward. Each binary you build will be linked against a specific library. It cannot be otherwise, because there are manifold name collisions between the v2 and v3 libraries.
If you are willing to abstract your Gtk usage, however, so as to provide for pluggable back-ends, then you could provide both Gtk+2 and Gtk+3 back-ends. And others, too. But this is non-trivial, especially if you've already written the application with direct Gtk calls.