As some of you might know, I am working on various G’MIC related projects, and for that I compile and work with the sources and libraries on various platforms like Windows, MacOS and Linux all the time.
Here are some of my personal experiences and insights with different compilers and operating systems when compiling G’MIC, maybe they are useful to some of you. Feel free to add/correct me if you know more about specific topics
*** COMPILING G’MIC ON WINDOWS ***
On Microsoft Windows, there are basically two approaches for compiling the G’MIC sources: either using the GNU C/C++ compiler collection (GCC) or using Microsoft Visual Studio.
The GCC approach is the recommended one (and also used for building the official G’MIC binaries).
I recommend installing MSYS2 (a Unix tool/emulation layer, available here http://www.msys2.org/) and using the MinGW compiler toolchain that comes with it. MSYS2 includes a nifty packet manager called “Pacman” that makes installing required third-party libraries and compilers a breeze.
I wrote a detailed description on how to set the whole toolchain up on Windows using this and then compile G’MIC with it. This information will be published soon on my website.
I tested it with the latest GCC version (GCC 7.1.0 from May 2017) and no changes to the Makefile were necessary. I linked against the libjpeg, libpng, libtiff, fftw3 OpenMP, OpenCV and curl libraries and it gets compiled within some minutes with full optimisations ("-O3" option).
One thing to note is that because in the Makefile display of all compiler warnings is enabled ("-Wall" option), you might get a lot of (harmless) warnings in the G’MIC sources. Particularly the new “fallthrough warning” in GCC when you use the “case” option in a “switch” statement without a “break” for each option will appear quite often, but it can be disabled with the “-Wimplicit-fallthrough=0” switch.
Now there is also the option of compiling with Microsoft’s own Visual Studio, although that still has some severe disadvantages:
G’MIC extensively uses a compiler feature called OpenMP (http://www.openmp.org/) that automatically runs certain code parts in parallel, making them faster. The G’MIC sources use OpenMP 3.x or above based commands, available in the GCC compiler suite for a long time. Microsoft Visual Studio however only supports OpenMP 2.0 and only in their commercial suite of compilers, not in the freely available ones. You therefore have to disable OpenMP support for Visual Studio builds, making certain complex G’MIC algorithms much slower.
The other big disadvantage is that the Microsoft compiler has problems with optimisation turned on when the code is extensively using nested templates and macros. This has been acknowledged by Microsoft since several years, but no remedy is in sight. In our case that means that the G’MIC sources compile within some seconds when optimisations are switched off, but when they are on, it might take literally hours to build (I recently stopped at about 5 hours compilation time!).
So, yes, you can build G’MIC in Visual Studio, but only without parallel processing and optimisations. I was surprised however that even the reduced build ran for the most basic operations at a similar speed as the GCC compiled one. Of course, the more complex and computation-intensive a G’MIC command/algorithm is, the more recognizable the difference will be.
It might still be a worthwhile road to follow if you have a Visual Studio project that you directly want to integrate with G’MIC. If you don’t want to use this compromise, but are bound to Visual Studio still, there is another option: some years ago I introduced an ANSI-C interface to G’MIC that makes its functionality accessible across compilers. So we can now build a fully optimized G’MIC library in GCC for example and then use the libcgmic/libcgmicstatic import library in Visual Studio to reference and use this. Best of both worlds for some
I created Visual Studio solutions/projects to build the various G’MIC components from there, these will also be published soon, probably in the G’MIC community repository where also my C interface resides.
Another problem some developers on Windows with Visual Studio might face is that you need exactly the right third-party libraries for that compiler and its project settings, which might be quite difficult to set up. Therefore I have also created Visual Studio project files for the sources for various open-source libraries like libjpeg, libpng, libtiff, libcurl, fftw3, zlib, pthreads, etc. If there is interest in these, I will also make them available to the public.
*** COMPILING G’MIC ON MAC OS ***
Moving on to the Apple desktop operating system.
Since this has an underlying Unix-derived base, some things are a bit easier to set up.
MacOS is however lacking a standard packet manager to install all the needed dependency libraries. You can of course compile and set them up manually, but I recommend using one of the existing free third-party packet managers. The most common ones seem to be “Fink” (http://www.finkproject.org/), “MacPorts” (https://www.macports.org/) and “Homebrew” (https://brew.sh/).
I think KaRo’s G’MIC Mac builds (http://karo03.bplaced.de/gmic/release/) are linked against MacPorts, but I wanted to try something new and used the newest of the bunch, “Homebrew”. It is really easy to install and get the required bundles, so the libjpeg, libpng, opencv, etc. stuff were available in no time.
The Makefile could also be used without modifications once all the required libraries were present. Interestingly, on my Mac OS X 10.11 system, I ran into a similar problem as on Windows with Visual Studio: when optimisations were on full ("-O3"), it took ages to compile (I stopped after 3 hours). Setting it one level lower to “-O2” brought it down to minutes and disabling optimisations alltogether made it compile really fast. Not sure if anyone has any recommendations/insights how this could be improved.
Another problem I ran into on MacOS is however that by default in the Makefile, MacOS builds are compiled against the X11 (standard X.Org X Window System) display library for G’MIC. However since MacOS 10.8, Apple decided to deprecate this and now longer ships supporting libraries and applications for it. The recommended solution for this is to install the open-source application XQuartz (https://www.xquartz.org/) which brings back X11 support for MacOS. Once installed, G’MIC then also runs fine with its X11 display.
Does anyone know if there is an alternative to X11 for G’MIC display on MacOS? Either possible at the moment or planned in the future? Any input would be appreciated.
*** COMPILING G’MIC ON LINUX ***
Now that is of course relatively easy - given that you have all the required libraries and headers available to link/compile against. On my Ubuntu 15.10 system it was relatively easy to set up and compile with full features. For “libtiff” and “curl” I had to make sure I had the specific versions installed that the compiler requires and modify some symbolic links on my system for the include paths.
Well, so that is my experiences from the last week trying to compile the most recent G’MIC sources (2.0.3pre) on various operating systems with different compilers. As I said, I will make all the info and project files I added myself available in the next weeks, maybe it helps others as well.