Linking to boost::iostreams, frustrated.
Dear all,
I have tried several hours to link to a mingw built boost_iostreams
under windows without success. Out of desperation, I turned to linux
where I have a boost/cvs installed. Using a very simple test program:
#include
g++ -I/usr/include/boost-1_35 -lboost_iostreams-gcc34-d test.cpp would success and run fine, but g++ -I/usr/include/boost-1_35 -static -lboost__iostreams-gcc34-d test.cpp will generate a bunch of undefined references like:
/tmp/cc2T22tx.o(.text+0x1af): In function `main':
: undefined reference to `boost::iostreams::zlib::default_strategy'
/tmp/cc2T22tx.o(.text+0x1c0): In function `main':
: undefined reference to `boost::iostreams::zlib::deflated'
/tmp/cc2T22tx.o(.text+0x1c6): In function `main':
: undefined reference to `boost::iostreams::zlib::default_compression'
/tmp/cc2T22tx.o(.gnu.linkonce.t._ZN5boost9iostreams21basic_gzip_compressorISaIcEEC1ERKNS0_11gzip_paramsEi+0x1e8):
In function `boost::iostreams::basic_gzip_compressor ::basic_gzip_compressor(boost::iostreams::gzip_params const&, int)': Can anyone guess what is going on?
Bo
Bo Peng wrote:
g++ -I/usr/include/boost-1_35 -static -lboost__iostreams-gcc34-d test.cpp will generate a bunch of undefined references like:
/tmp/cc2T22tx.o(.text+0x1af): In function `main': : undefined reference to `boost::iostreams::zlib::default_strategy'
[...]
Can anyone guess what is going on?
Boost.Iostreams needs extern zlib, bzip2, etc, just as the message show you. Regards cg
Boost.Iostreams needs extern zlib, bzip2, etc, just as the message show you.
The error message would be the same if I add them. The actual problem is linking order. Namely, $ g++ -static -lboost_iostreams -lz -lbz2 test.cpp fails, and $ g++ -static test.cpp -lboost_iostreams -lz -lbz2 succeeds. Why did $ g++ -shared -lboost_iostream -lz -lbz2 test.cpp succeed is beyond me. Anyway, linking under mingw still fails. Cheers, Bo
I guess this is a boost/bjam bug... What I did was: 1. download and uncompress boost-1.33.1, build bjam.exe 2. download official zlib package and unpack to c:\zlib 3. run $ bjam -sTOOLS=mingw -sNO_COMPRESSION=0 -sNO_BZIP2=1 -sNO_ZLIB=0 -sZLIB_INCLUDE=c:/zlib/include -sZLIB_LIBPATH=cL/zlib/lib -sZLIB_BINARY=zdll --prefix=c:/boost --with-iostreams install bjam says something like bzip2 support is disabled, which I interpret as zlib is supported, and produces .lib, .dll without problem. 4. After numerous failed links, I had a look at boost_1_33_1\bin\boost\libs\iostreams\build\libboost_iostreams.lib\mingw\debug and found only two object files, no zlib.obj! 5. I read the manual again and see ZLIB_SOURCE needs to be specified, I download zlib source, and add option -sZLIB_SOURCE=c:\zlib\src. This time, I get error message: unknown dependent target <@boost!libs!build>libboost_zlib.lib. 6. If I copy the iostream source files (except for bzip2.cpp) to my project and compile, everything is OK and no zlib source is ever needed. Conclusions: 1. bjam should report error if NO_COMPRESSION=0 and NO_ZLIB=0, but zlib.cpp can not be compiled for any reason. 2. Why zlib source is needed? 3. How can I build iostreams with zlib under windows/mingw? Many thanks in advance. Bo
On 12/21/06, Bo Peng
I guess this is a boost/bjam bug... What I did was:
Dear list, Is there a way to let bjam print out the exact commands it executes? Is there a log file somewhere? To temporarily fix the problem, I would like to add zlib.cpp by hand, but I do not know how bjam/boost/mingw generate the dll. Thanks. Bo
Hi Bo ! On Thursday 21 December 2006 16:10, Bo Peng wrote:
On 12/21/06, Bo Peng
wrote:
Is there a way to let bjam print out the exact commands it executes?
Try "-d+2" to print the _exact_ commandlines. Or try "-n" which will _only_ print the commandlines. Should be faster...
Is there a log file somewhere? To temporarily fix the problem, I would like to add zlib.cpp by hand, but I do not know how bjam/boost/mingw generate the dll.
Take a look at libs/iostreams/build/Jamfile.v2 . You'll see that there are options to either completely disable zlib or built it by itself. To get more help, you could try to run bjam --debug-configuration to see what bjam has found. And the order of libraries is relevant when doing static linking with gcc. It would be nice to know whether the link lines contain " -Wl,--start-group" and "-Wl,--end-group" which are used to navigate around this difficult area. Yours, Jürgen -- * Dipl.-Math. Jürgen Hunold ! Ingenieurgesellschaft für * voice: ++49 511 262926 57 ! Verkehrs- und Eisenbahnwesen mbH * fax : ++49 511 262926 99 ! Lister Straße 15 * juergen.hunold@ivembh.de ! www.ivembh.de
On 12/20/06, Bo Peng
$ g++ -static -lboost_iostreams -lz -lbz2 test.cpp fails, and
$ g++ -static test.cpp -lboost_iostreams -lz -lbz2 succeeds. Why did
$ g++ -shared -lboost_iostream -lz -lbz2 test.cpp succeed is beyond me.
When you use static libraries, only the symbols you need are taken from the static libraries. In the first command line, it performs that process before compiling test.cpp, so no symbols are needed, so none are taken. In the second, it compiles test.cpp first so it knows which symbols you need from the static libraries. For the third case, linking to shared libraries doesn't only take the symbols needed, for obvious reasons, so all the symbols you need (and those you don't) are defined before test.cpp gets compiled. ~ Scott McMurray
participants (4)
-
Bo Peng
-
gchen
-
Juergen Hunold
-
me22