odbc icon indicating copy to clipboard operation
odbc copied to clipboard

Error compiling odbc for R Studio in FreeBSD

Open Zamana opened this issue 3 years ago • 2 comments
trafficstars

Issue Description and Expected Result

Can't compile odbc package for RStudio in FreeBSD

Database

No database involved

Reproducible Example

The odbc R package is installed, but when I try to update it, I got this error:

c++ -std=gnu++11 -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -DLIBICONV_PLUG -isystem /usr/local/include   -Wall -Iinclude -std=c++11 -pthread  -O -fpic -MMD  -c -o time_zone_info.o src/time_zone_info.cc
src/time_zone_info.cc:64:10: error: cannot initialize return object of type 'char *' with an rvalue of type 'int'
  return strerror_r(errnum, buf, buflen);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
gmake[1]: Leaving directory '/tmp/Rtmp5OuFem/R.INSTALL11fa45c26d6f3/odbc/src/cctz'
gmake[1]: *** [<builtin>: time_zone_info.o] Error 1
gmake: *** [Makevars:16: cctz/libcctz.a] Error 2
ERROR: compilation failed for package ‘odbc’
* removing ‘/usr/home/zamana/R/amd64-portbld-freebsd12.2-library/4.1/odbc’
Warning in install.packages :
  installation of package ‘odbc’ had non-zero exit status

The C++ compiler used:

# c++ --version
FreeBSD clang version 10.0.1 ([email protected]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd12.2
Thread model: posix
InstalledDir: /usr/bin

Zamana avatar Dec 20 '21 23:12 Zamana

It looks like there are two versions of strerror_r(), one that returns an int and one that returns a char* depending on how compliant the system is

https://linux.die.net/man/3/strerror_r

int strerror_r(int errnum, char *buf, size_t buflen);
            /* XSI-compliant */

char *strerror_r(int errnum, char *buf, size_t buflen);
            /* GNU-specific */

so this system must be using the XSI compliant one

DavisVaughan avatar Dec 21 '21 18:12 DavisVaughan

Thanks for reply.

Is there something that I can do about?

Zamana avatar Dec 21 '21 19:12 Zamana

It looks like in 2017 they actually fixed the bug in cctz itself due to another r user report https://github.com/google/cctz/issues/40

that corresponded to this commit https://github.com/google/cctz/commit/8775f882d30fa25d5b142ca8a33b1049985aeffe

but then later that year they did another commit that removed usage of strerror_r() altogether (line 56 of time_zone_info.cc) https://github.com/google/cctz/commit/05f52fe89938f9755e35ba7877af19a813f8385b

so i think if we just update the embedded cctz then it will just magically fix itself.


We would need to be a little careful to reapply any necessary patches that have been made to cctz for CRAN over the years, but it doesn't look horrible? Some of these magically go away since strerror_r() is no longer being used (like the Alpine Linux one with __MUSL__)

https://github.com/r-dbi/odbc/commits/main/src/cctz

DavisVaughan avatar Apr 24 '23 14:04 DavisVaughan

You also should not need to re-apply this PR https://github.com/r-dbi/odbc/pull/440

CCTZ has fixed this upstream by naming the types that go in the anonymous union https://github.com/google/cctz/pull/84

DavisVaughan avatar Apr 24 '23 15:04 DavisVaughan