views:

384

answers:

1

UPDATE: Found a way to make it compile, see below.

Hello, I'm having issues compiling boost programs under cygwin. I've installed the default boost and g++ packages from the cygwin project's setup.exe.

On my Linux systems, I can compile a program reg.cpp using the following:

g++ -I/usr/include/boost -lboost_regex -o reg reg.cpp

On cygwin I have to edit this just a bit:

g++ -I/usr/include/boost-1_33_1 -lboost_regex-gcc-mt -o reg reg.cpp

The problem is that the cygwin version causes the linker to pull up a million undefined reference errors. The same thing happens trying to use the boost test framework libraries.

The linker is finding boost_regex-gcc-mt, but it doesn't appear to match the include file. Here's the first linker error:

undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'

HOW TO COMPILE

I found a solution here To compile, I did the following:

g++ -I/usr/include/boost-1_33_1 reg.cpp -o reg -lboost_regex-gcc-mt

According to the post, it has something to do with linker order. Anybody got a clue why this matters in cygwin but not modern Linux?

+1  A: 

It turns out that linkers traditionally process libraries from right to left. Most linkers don't care about library placement, but cygwin does. So the boost_regex library has to go at the end.

thras