eddelbuettel / bh

R package providing Boost Header files
84 stars 33 forks source link

Undefined reference to `scoped_static_mutex_lock` on Windows R 3.6 #93

Closed miserman closed 1 year ago

miserman commented 1 year ago

I don't know if it will want changes, but I ran into this issue when trying to compile this on Windows and R 3.6 specifically:

Rcpp::sourceCpp(code = '
  // [[Rcpp::depends(BH)]]
  #include <Rcpp.h>
  #include <boost/regex.hpp>

  // [[Rcpp::export]]
  bool startswith_a(std::string term) {
    boost::regex a("^a");
    return boost::regex_match(term, a);
  }
')
C:/Rtools/mingw_64/bin/g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG   -I"C:/Users/Username/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/Username/Documents/R/win-library/3.6/BH/include" -I"C:/Users/Username/AppData/Local/Temp/RtmpIzbuqE/sourceCpp-x86_64-w64-mingw32-1.0.11"        -O2 -Wall  -mtune=core2 -c file7894567d42f4.cpp -o file7894567d42f4.o
C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -shared -s -static-libgcc -o sourceCpp_103.dll tmp.def file7894567d42f4.o -LC:/PROGRA~1/R/R-36~1.3/bin/x64 -lR
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv]+0x1f): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv]+0x3f): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv]+0xa2): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y[_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y]+0x27): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y[_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y]+0x44): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
file7894567d42f4.o:file7894567d42f4.cpp:(.text$_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y[_ZN5boost12object_cacheINS_13re_detail_50021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_y]+0xa7): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2.exe: error: ld returned 1 exit status

But that works when defining either BOOST_REGEX_STANDALONE or BOOST_REGEX_USE_C_LOCALE (as far as I tested) beforehand:

Rcpp::sourceCpp(code = '
  // [[Rcpp::depends(BH)]]
  #include <Rcpp.h>
  #define BOOST_REGEX_USE_C_LOCALE
  #include <boost/regex.hpp>

  // [[Rcpp::export]]
  bool startswith_a(std::string term) {
    boost::regex a("^a");
    return boost::regex_match(term, a);
  }
')

I'm not sure why those work or what difference they might make, so, if defining those is an acceptable solution, I wonder:

eddelbuettel commented 1 year ago

Boost regex is, sadly, one of the Boost libraries that cannot used only with BH as they require linking. So this is outside the scope of the package.

The package README hints at his:

Note that this can be used solely by headers-only Boost libraries. This covers most of Boost, but excludes some libraries which require linking for parts or all of their functionality.