ufal / udpipe

UDPipe: Trainable pipeline for tokenizing, tagging, lemmatizing and parsing Universal Treebanks and other CoNLL-U files
Mozilla Public License 2.0
358 stars 75 forks source link

error on Solaris #44

Closed jwijffels closed 6 years ago

jwijffels commented 6 years ago

Hi,

As the CRAN build farm gives an error when building on Solaris, I'm trying to fix the build errors, so that the package gets accepted by CRAN. When I build the package on Solaris (which is configured as follows: https://www.stats.ox.ac.uk/pub/bdr/Rconfig/r-patched-solaris-x86). with the fix and command explained in issue #43 I still get errors. I've put these below.

This looks like udpipe.cpp does not use cmath but math.h If I look for a solution on this, I see http://kevinushey.github.io/blog/2016/09/14/pitfalls-in-writing-portable-c++98-code/ which pretty much resembles the issues that are raised when building this on Solaris.

Standard Library Headers

The following code may fail to compile on Solaris:

#include <cstring>
size_t string_length(const char* string) {
  return ::strlen(string);
}

kevin@soularis:~/scratch
$ CC -library=stlport4 string_length.cpp 
"string_length.cpp", line 3: Error: size_t is not defined.
"string_length.cpp", line 4: Error: strlen is not defined.
2 Error(s) detected.

The C++ standard library headers that ‘wrap’ their C counterparts are typically prefixed with a c and contain no extension, e.g. <cstring>; while the C headers themselves are typically given a .h extension, e.g. <string.h>. When the <cstring> header is included in a translation unit, the C++98 standard dictates that the compiler:

    Must define its members (e.g. strlen) in the std:: namespace, and
    May define its members (e.g. strlen) in the global namespace.

In fact, gcc and clang both accept the above code, but the Solaris compilers do not. (The Solaris compilers do not populate the global namespace when including these headers.)

    Rule: If you include a C++-style standard library header, reference symbols from the std namespace. Prefer using C++-style standard library headers over the original C counterpart. Prefer referencing these symbols explicitly, with the std:: prefix.

How can this be fixed in ufal/udpipe? The following shows the error from building the package:

/opt/csw/bin/g++ -std=gnu++11 -I/opt/R/R-3.4.1-patched-gcc/lib/R/include -DNDEBUG  -I"/export/home/X8MNlSX/R/Rcpp/include" -I/opt/csw/include -I/usr/local/include   -fPIC  -O2 -c RcppExports.cpp -o RcppExports.o
In file included from /opt/csw/include/c++/5.2.0/cmath:44:0,
                 from /export/home/X8MNlSX/R/Rcpp/include/Rcpp/platform/compiler.h:100,
                 from /export/home/X8MNlSX/R/Rcpp/include/Rcpp/r/headers.h:48,
                 from /export/home/X8MNlSX/R/Rcpp/include/RcppCommon.h:29,
                 from /export/home/X8MNlSX/R/Rcpp/include/Rcpp.h:27,
                 from RcppExports.cpp:4:
/usr/include/math.h:45:12: error: ‘std::float_t’ has not been declared
 using std::float_t;
            ^
/usr/include/math.h:46:12: error: ‘std::double_t’ has not been declared
 using std::double_t;
            ^
/usr/include/math.h:48:12: error: ‘std::fpclassify’ has not been declared
 using std::fpclassify;
            ^
/usr/include/math.h:49:12: error: ‘std::isfinite’ has not been declared
 using std::isfinite;
            ^
/usr/include/math.h:50:12: error: ‘std::isinf’ has not been declared
 using std::isinf;
            ^
/usr/include/math.h:51:12: error: ‘std::isnan’ has not been declared
 using std::isnan;
            ^
/usr/include/math.h:52:12: error: ‘std::isnormal’ has not been declared
 using std::isnormal;
            ^
/usr/include/math.h:53:12: error: ‘std::signbit’ has not been declared
 using std::signbit;
            ^
/usr/include/math.h:55:12: error: ‘std::isgreater’ has not been declared
 using std::isgreater;
            ^
/usr/include/math.h:56:12: error: ‘std::isgreaterequal’ has not been declared
 using std::isgreaterequal;
            ^
/usr/include/math.h:57:12: error: ‘std::isless’ has not been declared
 using std::isless;
            ^
/usr/include/math.h:58:12: error: ‘std::islessequal’ has not been declared
 using std::islessequal;
            ^
/usr/include/math.h:59:12: error: ‘std::islessgreater’ has not been declared
 using std::islessgreater;
            ^
/usr/include/math.h:60:12: error: ‘std::isunordered’ has not been declared
 using std::isunordered;
            ^
/usr/include/math.h:62:12: error: ‘std::acosh’ has not been declared
 using std::acosh;
            ^
/usr/include/math.h:63:12: error: ‘std::asinh’ has not been declared
 using std::asinh;
            ^
/usr/include/math.h:64:12: error: ‘std::atanh’ has not been declared
 using std::atanh;
            ^
/usr/include/math.h:65:12: error: ‘std::cbrt’ has not been declared
 using std::cbrt;
            ^
/usr/include/math.h:66:12: error: ‘std::copysign’ has not been declared
 using std::copysign;
            ^
/usr/include/math.h:67:12: error: ‘std::erf’ has not been declared
 using std::erf;
            ^
/usr/include/math.h:68:12: error: ‘std::erfc’ has not been declared
 using std::erfc;
            ^
/usr/include/math.h:69:12: error: ‘std::exp2’ has not been declared
 using std::exp2;
            ^
/usr/include/math.h:70:12: error: ‘std::expm1’ has not been declared
 using std::expm1;
            ^
/usr/include/math.h:71:12: error: ‘std::fdim’ has not been declared
 using std::fdim;
            ^
/usr/include/math.h:72:12: error: ‘std::fma’ has not been declared
 using std::fma;
            ^
/usr/include/math.h:73:12: error: ‘std::fmax’ has not been declared
 using std::fmax;
            ^
/usr/include/math.h:74:12: error: ‘std::fmin’ has not been declared
 using std::fmin;
            ^
/usr/include/math.h:75:12: error: ‘std::hypot’ has not been declared
 using std::hypot;
            ^
/usr/include/math.h:76:12: error: ‘std::ilogb’ has not been declared
 using std::ilogb;
            ^
/usr/include/math.h:77:12: error: ‘std::lgamma’ has not been declared
 using std::lgamma;
            ^
/usr/include/math.h:78:12: error: ‘std::llrint’ has not been declared
 using std::llrint;
            ^
/usr/include/math.h:79:12: error: ‘std::llround’ has not been declared
 using std::llround;
            ^
/usr/include/math.h:80:12: error: ‘std::log1p’ has not been declared
 using std::log1p;
            ^
/usr/include/math.h:81:12: error: ‘std::log2’ has not been declared
 using std::log2;
            ^
/usr/include/math.h:82:12: error: ‘std::logb’ has not been declared
 using std::logb;
            ^
/usr/include/math.h:83:12: error: ‘std::lrint’ has not been declared
 using std::lrint;
            ^
/usr/include/math.h:84:12: error: ‘std::lround’ has not been declared
 using std::lround;
            ^
/usr/include/math.h:85:12: error: ‘std::nan’ has not been declared
 using std::nan;
            ^
/usr/include/math.h:86:12: error: ‘std::nanf’ has not been declared
 using std::nanf;
            ^
/usr/include/math.h:87:12: error: ‘std::nanl’ has not been declared
 using std::nanl;
            ^
/usr/include/math.h:88:12: error: ‘std::nearbyint’ has not been declared
 using std::nearbyint;
            ^
/usr/include/math.h:89:12: error: ‘std::nextafter’ has not been declared
 using std::nextafter;
            ^
/usr/include/math.h:90:12: error: ‘std::nexttoward’ has not been declared
 using std::nexttoward;
            ^
/usr/include/math.h:91:12: error: ‘std::remainder’ has not been declared
 using std::remainder;
            ^
/usr/include/math.h:92:12: error: ‘std::remquo’ has not been declared
 using std::remquo;
            ^
/usr/include/math.h:93:12: error: ‘std::rint’ has not been declared
 using std::rint;
            ^
/usr/include/math.h:94:12: error: ‘std::round’ has not been declared
 using std::round;
            ^
/usr/include/math.h:95:12: error: ‘std::scalbln’ has not been declared
 using std::scalbln;
            ^
/usr/include/math.h:96:12: error: ‘std::scalbn’ has not been declared
 using std::scalbn;
            ^
/usr/include/math.h:97:12: error: ‘std::tgamma’ has not been declared
 using std::tgamma;
            ^
/usr/include/math.h:98:12: error: ‘std::trunc’ has not been declared
 using std::trunc;
            ^
gmake: *** [/opt/R/R-3.4.1-patched-gcc/lib/R/etc/Makeconf:168: RcppExports.o] Error 1
foxik commented 6 years ago

This is really weird. UDPipe does not use math.h, all includes are at the top of the file and you can verify that it correctly uses cmath.

Also note that in the error log file trace, no udpipe source is mentioned. The compilation fails during compilation of RcppExports.cpp and the chain leading to math.h avoids udpipe completely. So it seems that either the Rcpp* files are wrong, or the whole compiler is somehow broken. (In #43, the udpipe.cpp was compiled as a third file; here the compilation fails during the compilation of the first one.)

jwijffels commented 6 years ago

Thanks for the feedback. I'll do some more research to find the root cause.

jwijffels commented 6 years ago

It was fixed by incorporating pull request #54

foxik commented 6 years ago

Instead of #54, I tried to fix this in e5ec349.