安装特定版本的 R pgmm 库失败

安装特定版本的 R pgmm 库失败

我正在尝试安装 R 中 pgmm 库的特定版本,但失败了:

> library(fs)
> old_lib <- path_home_r("R/x86_64-pc-linux-gnu-library/old-versions/")
> library(remotes)
> install_version("pgmm", version = "1.1", lib = old_lib, build = TRUE)
Downloading package from url: https://cloud.r-project.org/src/contrib/Archive/pgmm/pgmm_1.1.tar.gz
Running `R CMD build`...
* checking for file ‘/tmp/Rtmp6Jj3B0/remotes3b5e8d11b5fe/pgmm/DESCRIPTION’ ... OK
* preparing ‘pgmm’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a ‘data/datalist’ file should be added
* building ‘pgmm_1.1.tar.gz’
* installing *source* package ‘pgmm’ ...
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-PsrVor/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c aecm.c -o aecm.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-PsrVor/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c gaussj.c -o gaussj.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-PsrVor/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c myalloc.c -o myalloc.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-PsrVor/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c pgmm.c -o pgmm.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-PsrVor/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c updates.c -o updates.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o pgmm.so aecm.o gaussj.o myalloc.o pgmm.o updates.o -L/usr/lib/R/lib -lR
/usr/bin/ld: gaussj.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: multiple definition of `testfunc2'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: first defined here
/usr/bin/ld: gaussj.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: multiple definition of `testfunc'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: first defined here
/usr/bin/ld: myalloc.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: multiple definition of `testfunc2'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: first defined here
/usr/bin/ld: myalloc.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: multiple definition of `testfunc'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: first defined here
/usr/bin/ld: pgmm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: multiple definition of `testfunc2'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: first defined here
/usr/bin/ld: pgmm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: multiple definition of `testfunc'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: first defined here
/usr/bin/ld: updates.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: multiple definition of `testfunc2'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:4: first defined here
/usr/bin/ld: updates.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: multiple definition of `testfunc'; aecm.o:/tmp/RtmpGlEBF9/R.INSTALL3b70d1f18017d/pgmm/src/functions.h:1: first defined here
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:6: pgmm.so] Error 1
ERROR: compilation failed for package ‘pgmm’
* removing ‘/home/eric/R/x86_64-pc-linux-gnu-library/old-versions/pgmm’
Warning message:
In i.p(...) :
  installation of package ‘/tmp/Rtmp6Jj3B0/file3b5e87e350a98/pgmm_1.1.tar.gz’ had non-zero exit status

“R/x86_64-pc-linux-gnu-library/old-versions/”目录存在,并且1.1 版本的 pgmm软件包也存在。任何修复建议都非常感谢。

答案1

在 Ubuntu 20.10 上,可以使用 gcc-9 安装 pgmm 1.1:

sudo apt-get install gcc-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9

然后编译R包。

要将 gcc 版本恢复为默认版本,请使用以下命令:

sudo update-alternatives --remove-all gcc

答案2

该问题与 R pgmm 的特定版本无关,而是与任何不符合指南的 R 扩展有关编写 R 扩展:1.6.4.1 常用符号使用 GCC 10 及更高版本构建时。

我们可以使用functions.h从 复制的最少内容pgmm/src以及包含它的几个最小 C 源文件进行演示:

$ head functions.h A.c B.c
==> functions.h <==
double (*testfunc)(double **, double **, int *,int,int,int,int,double *,double *,double);
typedef typeof(testfunc) funcType;

double (*testfunc2)(double **, double **,int,int,int,int,double *,double *,double);
typedef typeof(testfunc2) funcType2;

==> A.c <==
#include "functions.h"

==> B.c <==
#include "functions.h"

然后使用 GCC 10,使用默认值-fno-common

$ make CC=gcc-10 A.o B.o
gcc-10    -c -o A.o A.c
gcc-10    -c -o B.o B.c
$ gcc -shared A.o B.o && echo "OK" || echo "FAILED"
/usr/bin/ld: B.o:(.bss+0x0): multiple definition of `testfunc'; A.o:(.bss+0x0): first defined here
/usr/bin/ld: B.o:(.bss+0x8): multiple definition of `testfunc2'; A.o:(.bss+0x8): first defined here
collect2: error: ld returned 1 exit status
FAILED

-fcommon

$ rm *.o
$ make CC=gcc-10 CFLAGS=-fcommon A.o B.o
gcc-10 -fcommon   -c -o A.o A.c
gcc-10 -fcommon   -c -o B.o B.c
$ gcc -shared A.o B.o && echo "OK" || echo "FAILED"
OK
$

解决方案是使用旧版本的 GCC 进行构建,或者自定义 R 构建过程,如R 安装和管理:6.3.3 自定义包编译-fcommon通过变量传递选项CFLAGS

也可以看看:

相关内容