ua-parser / uap-r

R implementation of ua-parser
Other
14 stars 13 forks source link

Fails testing - Library not loaded: libboost_regex.dylib #10

Open btskinner opened 8 years ago

btskinner commented 8 years ago

I'm using OS X 10.11.3 (El Capitan) and calling R from the Terminal. libboost_regex.dylib exists in /usr/local/lib. All other dependencies are installed (I believe). Here's the output.

> devtools::install_github("ua-parser/uap-r")
Downloading GitHub repo ua-parser/uap-r@master
from URL https://api.github.com/repos/ua-parser/uap-r/zipball/master
Installing uaparser
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ  \
  --no-save --no-restore CMD INSTALL  \
  '/private/var/folders/p7/5ylvzpld32x89bnkw42jj7dw0000gr/T/RtmpqhWpde/devtoolscdde29e38543/ua-parser-uap-r-cbfdc17'  \
  --library='/Library/Frameworks/R.framework/Versions/3.2/Resources/library'  \
  --install-tests 

* installing *source* package ‘uaparser’ ...
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for R... yes
checking for Rscript... yes
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ -arch x86_64 -ftemplate-depth-256 accepts -g... yes
checking for boostlib >= 1.4... yes
checking whether the Boost::Regex library is available... yes
checking for exit in -lboost_regex... yes
** libs
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include     -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"   -fPIC  -Wall -mtune=core2 -g -O2 -c RcppExports.cpp -o RcppExports.o
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include     -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"   -fPIC  -Wall -mtune=core2 -g -O2 -c internal_UaParser.cpp -o internal_UaParser.o
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include     -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"   -fPIC  -Wall -mtune=core2 -g -O2 -c internal_ua_parser.cpp -o internal_ua_parser.o
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include     -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"   -fPIC  -Wall -mtune=core2 -g -O2 -c ua_parse.cpp -o ua_parse.o
clang++ -std=c++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o uaparser.so RcppExports.o internal_UaParser.o internal_ua_parser.o ua_parse.o -lboost_regex -lboost_system -lyaml-cpp -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.2/Resources/library/uaparser/libs
** R
** inst
** 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 '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/uaparser/libs/uaparser.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/uaparser/libs/uaparser.so, 6): Library not loaded: libboost_regex.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/uaparser/libs/uaparser.so
  Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/uaparser’
Error: Command failed (1)
Ironholds commented 8 years ago

Yeah, I've been encountering a similar issue, and I'm not sure why. I'll try to look into it next week.

btskinner commented 8 years ago

I have an update. I was able to install and load the package after adding symbolic links for libboost_regex.dylib and libboost_system.dylib to /Library/Frameworks/R.framework/Libraries (which I guess is itself a link to /Library/Frameworks/R.framework/Versions/Current/Resources/lib). Both libraries are installed in /usr/local/lib, which is in the environment path, but this was what it took to get everything working. Package successfully loaded and tested on some user agent strings. Thanks!

Ironholds commented 8 years ago

NP! Hmn. Is it a problem with the makefile? i.e., should this lib be looking in more places? I'm not sure how much we can modify Rcpp imports, unfortunately, but if I can I will.

btskinner commented 8 years ago

We're at the edges of my programming ability here, so I'm not sure how much I can help. Rcpp loads fine on my machine and did before this, so the way it does things is probably okay. I did notice this section in the R Installation and Administration manual (6.3.6):

On OS X the primary mechanism is to embed the absolute path to dependent dynamic libraries into an object when it is compiled. Few R packages arrange to do so, but it can be edited via install_name_tool — that only deals with direct dependencies and those would also need to be compiled to include the absolute paths of their dependencies. If the choice of absolute path is to be deferred to load time, how they are resolved is described in man dyld: the role of LD_LIBRARY_PATH is replaced on OS X by DYLD_LIBRARY_PATH and latterly DYLD_FALLBACK_LIBRARY_PATH. Running R CMD otool -L on the package shared object will show where (if anywhere) its dependencies are resolved. DYLD_FALLBACK_LIBRARY_PATH is preferred (and it is that which is manipulated by the R script), but as from 10.11 (‘El Capitan’) the default behaviour had been changed for security reasons to discard these environment variables when invoking a shell script (and R is a shell script). That makes the only portable option to set R_LD_LIBRARY_PATH in the environment, something like

export R_LD_LIBRARY_PATH="R RHOME/lib:/opt/local/lib"

I R CMD INSTALL --no-test-load the package and ran otool -L uaparser.so to confirm that, at least for me, all other libs were being linked, but the two boost *.dylibs weren't. I tried adding /usr/local/lib, where they are located, to R_LD_LIBRARY_PATH. I could see the path when I did a Sys.getenv() in R, but the installer didn't seem to be linking to it. Hence my manual symlinks. Since then, I realized that I spelled it incorrectly and fixed it; after that I was able to install the package without needing the symlinks.

I don't know the standard install paths for boost libraries, but at the moment it seems that one either needs those two lib files in the R fallback path (above) or have them added to the R_LD_LIBRARY_PATH in ~/.bash_profile.

Ironholds commented 8 years ago

Would you rather have it (a) work on Windows or (b) have full compatibility with the range of regexes used?

Basically it's not possible (or: exceedingly hard) to integrate with boost regex on every platform, but C++11 has regex support and now works there, so I can fall back to that - the problem being that it uses different syntax (EMACscript versus PCRE).

btskinner commented 8 years ago

Trying to get my head wrapped around this again. Could you use the BH package as a dependency? The README list of available libraries doesn't include system or regex, but I think the header files might be in there.

Ironholds commented 8 years ago

Alas, no - it needs linking (which is system-dependent) to work.

On Monday, 25 July 2016, Benjamin Skinner notifications@github.com wrote:

Trying to get my head wrapped around this again. Could you use the BH https://cran.r-project.org/web/packages/BH/index.html package as a dependency? The README list of available libraries doesn't include system or regex, but I think the header files might be in there https://github.com/eddelbuettel/bh/tree/master/inst/include/boost.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ua-parser/uap-r/issues/10#issuecomment-234941277, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXz3sgu6BKrKDc9P2btbGybBfPiBO7fks5qZK41gaJpZM4HZwSg .

btskinner commented 8 years ago

Reading the BH info a little more closely, I see that now. That's unfortunate. While I personally don't care that much about Windows support, it's probably better to go with (b).