Solved: Cannot find -lgcc_s on Cygwin 4.3.4
For the past week or so, I've been trying to build the Giza++ language modeling tools on my Windows machines, and have been having quite a bit of trouble. Permissions errors on Windows 7, weird "missing separator" error messages that were completely unhelpful (it means your text editor has replaced all tabs with spaces), and so on. Compile and build errors that have kept me up late into the night on several occasions lately, but which I was ultimately able to untangle with a little applied Google-Fu.
Despite my best efforts, though, I was stymied by this error:
g++ -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE optimized/Parameter.o optimized/myassert.o optimized/Perplexity.o optimized/model1.o optimized/model2.o optimized/model3.o optimized/getSentence.o optimized/TTables.o optimized/ATables.o optimized/AlignTables.o optimized/main.o optimized/NTables.o optimized/model2to3.o optimized/collCounts.o optimized/alignment.o optimized/vocab.o optimized/MoveSwapMatrix.o optimized/transpair_model3.o optimized/transpair_model5.o optimized/transpair_model4.o optimized/utility.o optimized/parse.o optimized/reports.o optimized/model3_viterbi.o optimized/model3_viterbi_with_tricks.o optimized/Dictionary.o optimized/model345-peg.o optimized/hmm.o optimized/HMMTables.o optimized/ForwardBackward.o -static -o GIZA++ /usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lgcc_s /usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lgcc_s collect2: ld returned 1 exit status make: *** [GIZA++] Error 1
My initial web searches didn't illuminate much: the "-lgcc_s" bit in the error report pointed to a problem with Libgcc, but that library is part of GCC, and Cygwin installs it just fine when you tell it to — I should know, I've (re)installed Cygwin on two different machines 3 times in the past few days! So, what could the problem possibly be...? Tonight, I finally found the answer, with a nudge in the right direction from this blog:
'-static' option makes gcc to avoid the use of shared libraries. '-static' is supposed to make gcc use -lgcc_s and '-dynamic' to make gcc use -lgcc. Actually, Cygwin and gcc 4.3.4 are not coming with 'libgcc_s.a'. Something's wrong, but I'm not sure here. Anyway, in order to compile, it is necessary to change '-static' to something. For instance, if '-static' was removed, it would be okay!
This reminded me of something I read in the "Getting Started" guide to Moses, the statistical machine translation system I'm trying to use as part of my Computational Linguistics MA thesis:
Aside from the questionable logic here ("we need to tweak two Makefiles", but then the second one "is OK"? Hmm, if you say so...), this clicked into place alongside what the first blog said. If OS X doesn't support static linking, I'm willing to bet that Cygwin on Windows doesn't either. I edited the Makefile — taking care to preserve the tabs on save this time — and made the suggested change to the LDFLAGS assignment line. This time, when I ran
make, it worked! Problem solved, finally.
Now, I can go to bed. :)