编译 Cairo R 包 - /usr/lib64/libcairo.a: 添加符号时出错:错误值

Compile Cairo R package - /usr/lib64/libcairo.a: error adding symbols: Bad value

我正在尝试从源代码(https://cran.r-project.org/web/packages/Cairo/index.html,最新版本)为 R3.2.4 编译 R 包 "Cairo"。

这是必需的,因为应该安装它的服务器(SLES11 SP4,没有更改选项)没有互联网连接,所以我无法从 repo 安装。

一些问题已经通过设置正确的环境变量解决了(见下面的设置)。 不幸的是,尝试安装软件包在配置后仍然给我一个编译错误。

设置:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64
export CAIRO_INCLUDE_PATH=/usr/include/cairo
export CAIRO_CFLAGS='-I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12'
export CAIRO_LIBS='-L/usr/lib64 -lcairo -lfreetype -lpixman-1 -lfontconfig -lpng12 -lz -lXrender -lX11'

输出(在 R 命令行上):

> install.packages("/home/username/R_packages/Cairo_1.5-9.tar.gz", type="source", repos=NULL)
* installing *source* package ‘Cairo’ ...
** package ‘Cairo’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
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 -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for pkg-config... /usr/bin/pkg-config
configure: CAIRO_CFLAGS=-I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-L/usr/lib64 -lcairo -lfreetype -lpixman-1 -lfontconfig -lpng12 -lz -lXrender -lX11
checking for library containing deflate... none required
checking whether Cairo programs can be compiled... yes
checking whether cairo_image_surface_get_format is declared... no
checking for FreeType support in cairo... yes
checking whether FreeType needs additional flags... no
checking wheter libjpeg works... no
checking wheter libtiff works... no
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating src/cconfig.h
** libs
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c cairobem.c -o cairobem.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c cairogd.c -o cairogd.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c cairotalk.c -o cairotalk.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c img-backend.c -o img-backend.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c img-jpeg.c -o img-jpeg.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c img-tiff.c -o img-tiff.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c pdf-backend.c -o pdf-backend.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c ps-backend.c -o ps-backend.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c svg-backend.c -o svg-backend.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c w32-backend.c -o w32-backend.o
gcc -std=gnu99 -I/home/username/R3/lib64/R/include -DNDEBUG -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/fontconfig -I/usr/include/libpng12  -I. -Iinclude -I/usr/local/include   -g -O2 -fpic  -g -O2  -c xlib-backend.c -o xlib-backend.o
gcc -std=gnu99 -shared -L/home/username/R3/lib64/R/lib -L/usr/local/lib64 -o Cairo.so cairobem.o cairogd.o cairotalk.o img-backend.o img-jpeg.o img-tiff.o pdf-backend.o ps-backend.o svg-backend.o w32-backend.o xlib-backend.o -L/usr/lib64 -lcairo -lfreetype -lpixman-1 -lfontconfig -lpng12 -lz -lXrender -lX11 -L/home/username/R3/lib64/R/lib -lR
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/libcairo.a(cairo.o): relocation R_X86_64_32 against `_cairo_pattern_nil' can not be used when making a shared object; recompile with -fPIC
/usr/lib64/libcairo.a: error adding symbols: Bad value
collect2: ld returned 1 exit status
make: *** [Cairo.so] Error 1
ERROR: compilation failed for package ‘Cairo’
* removing ‘/home/username/R3/lib64/R/library/Cairo’
Warning message:
In install.packages("/home/username/R_packages/Cairo_1.5-9.tar.gz",  :
  installation of package ‘/home/username/R_packages/Cairo_1.5-9.tar.gz’ had non-zero exit status

希望 gcc/ld/R 编译专家能告诉我哪里出了问题,我该如何解决。

谢谢,BadTenMan

问题是 /usr/lib64/ libcairo.so link 被破坏了:

ls -l /usr/lib64 |grep -i cairo
libcairo.a
libcairo.la
libcairo.so -> libcairo.so.2.10800.0
libcairo.so.2 -> libcairo.so.2.10800.8
libcairo.so.2.10800.8

没有 libcairo.so.2.10800.0,所以 ld linked libcairo.a。 将 link 修复为 libcairo.so。2.10800.8 解决了它。