eddelbuettel / bh

R package providing Boost Header files
85 stars 32 forks source link

Use of gzip #49

Closed sanglier91 closed 7 years ago

sanglier91 commented 7 years ago

Hi,

First of all thank you for this very useful package. I would like to use it inside a package to read a gzip file. At the end of the compilation, I get the following error message:

** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/xxxxxxxxxxxxx/NeutronMultiplicityCounting.so':
  /xxxxxxxxxxxxxxxxxxxxx/NeutronMultiplicityCounting/libs/NeutronMultiplicityCounting.so: undefined symbol: _ZN5boost9iostreams4zlib8deflatedE
Error: loading failed
Execution halted
ERROR: loading failed

I believe the error come from the header file <boost/iostreams/filter/gzip.hpp> that I need. It uses the zlib.hpp file that declare the following variable:

BOOST_IOSTREAMS_DECL extern const int deflated;

My DESCRIPTION file declare BH under the LinkingTo section.

I use other functions from BH without any problem.

I can solve the problem by adding the following line to my Makevars file but I guess this is not the right way to do:

PKG_LIBS = -L/usr/lib/x86_64-linux-gnu/ -lboost_iostreams -lboost_filesystem

Wilfried

eddelbuettel commented 7 years ago

I can take a look but note first that you do not need Boost to open gzip'ed file. R already does it via all of read.table() and variants, and you can also do it in plain C/C++ code via gzopen() -- which should also "just work" because R is always built wiith that library.

As for "I can solve it this" that is indeed correct, but your package now becomes less portable as all users would have to have these libraries available "and visible". Unlikely on Windows. In short, this is the difference between using Boost as header-only (as BH) or using Boost full-fledged with linking. Some libraries and components only work in the latter way. It is up to you balance those costs and benefits.

sanglier91 commented 7 years ago

I didn't know about gzopen(). I'm going to change my code in order to use it. Thank you. Please let me know if you find the reason of the error.

eddelbuettel commented 7 years ago

Yes, gzopen() is gold. Been using it for decades (!!).

I told you the error. The way Boost implements this requires linking with Boost.