Thursday, 7 June 2012

Building POCO C++ with Mingw

I've been looking for a logging framework for C++. I'd read about several options, but hadn't really found anything I felt like trying, until a couple of days ago, when I discovered POCO C++.

I decided to give it a try, but the README seemed to be warning me I was in for some Interesting Times(TM):

Microsoft Visual Studio 7.1 (2003), 8.0 (2005), 9.0 (2008) or 10.0 (2010) is required to build the POCO C++ Libraries on Windows platforms.

BTW, the emphasis is mine.

Still, nothing new, just another OSS telling users of OSS on Windows: "You're on your own".

Before I go on, I've solved these problems on my own, but if I had searched the POCO Forum, I would've saved some time, as someone had posted solutions to all the problems I found. I did google it, but sometimes google is not enough.

I fired Msys and ran configure. I didn't follow README's advice, however, and didn't run make -s. I prefer having as much info available as possible, thank you very much, so I ran it with --debug and -w.

The first problem came in the form of an unrecognized option: -mno-cygwin. I looked in the <POCO_HOME>/build/config/MinGW file, and found these lines:

SHLIB   = $(CXX) -shared -mno-cygwin -o $@ -Wl,--out-implib=$(dir $@)$(subst cyg,lib,$(basename $(notdir $@))).a

SYSFLAGS = -mno-cygwin -D_WIN32 -DMINGW32 -DWINVER=0x500 -DPOCO_NO_FPENVIRONMENT -DPCRE_STATIC -DPOCO_THREAD_STACK_SIZE -DFoundation_Config_INCLUDED -I/usr/local/include -I/usr/include

A couple of searches, and I realized this option didn't apply to my version of gcc, so I removed it.

Then, the linker complained it couldn't find OpenSSL libs ssl and crypto. Having built OpenSSL, I had those libs, so I added another -L to this line, pointing to the OpenSSL libs (once again, in <POCO_HOME>/build/config/MinGW file):

SYSLIBS  = -L/usr/local/lib -L/usr/lib -liphlpapi -lws2_32 -lssl -lcrypto -lws2_32 -lgdi32

Another go at make, and this time I got an error with strip. After making sure I hadn't inadvertently linked in my porn collection (it is rather sizable, and tends to show up in the most embarrassing places), I've decided to google strip. And then, naturally, strip command.

From what I've learned, it's nothing I should actually worry about at this stage, although it is something interesting to look into later on. So, I've decided to remove it from the <POCO_HOME>/build/config/MinGW file, by turning this

STRIP   = strip

into this


And there you go, we have build! I've built the Logger example, and I plan on giving it a try on my own project.

And now for something slightly completely different: A semi-rant...

MS is preparing to cripple the next version of VC++ Express, which the POCO C++ blog also refers in this post.

I fail to see what's the drama, actually. Maybe now all the people behind OSS can actually direct their effort at creating a better support for OSS on Windows, instead of just saying "There you go, have these VC++ files and enjoy".


  1. Did it occur to that you could help "people behind OSS" scratch your itch. We give hours of our work for free and it's still not enough?

    1. You're absolutely right.

      I did submit patches a couple of times:
      - for some examples on libssh2.
      - for a fix in a problem in one of POCO's logging classes, when a log file rolls over.

      AFAIK (I stopped following those), those patches went nowhere. Granted, those weren't even close to being top priority issues, but for a beginner like me, it still took time dive into the sources, understand (part of) what was going on, and work out a fix (which, I accept, may be of debatable quality).

      And I did it on my time. This is a personal learning experience, for which I'm not getting paid.

      The value of the work that's freely given to the world by OSS is unquestionable, and I am thankful for that (and, rereading what I wrote, I admit I should've been more explicit on this). If I didn't believe so, I wouldn't have turned to it (thankfully, I have money to spend on commercial tools, if I so desire).

      At the end of the day, I still chose to work with POCO C++, and I still spent my personal time figuring out how to build it on Windows with mingw. I wouldn't have done it if I thought it had no value.

      So, you give hours of your free time, and, yes, that is appreciated. I did the same (on a tiny scale, naturally), and I hope to continue doing it to the best of my ability. However, that won't keep me from pointing what I consider flaws on someone else's work, and it certainly shouldn't stop anyone from doing the same with my work.