読者です 読者をやめる 読者になる 読者になる

RffiをWindowsでビルドしようとしてるけどまったくうまくいかない...

R FFI Windows

つらい。

MobaXtermは、uname -mするとi686ってなってたので、64bit版がほしいからあきらめてMSYS2を使うことに。

Windows 10+MSYS2だとアーキテクチャを自動判定してくれなかったので、./configureには--buildで自分で指定しないといけない。よくわからないけど、Rtoolsにはi686^w64-mingw32と書いてあるのでそれを指定する。

cd libffi-3.0.9
./configure CC="/c/Rtools/gcc-4.6.3/bin/gcc.exe" CXX="/c/Rtools/gcc-4.6.3/bin/g++.exe" --build=i686-w64-mingw32

# README.winの助言に従う
rm include/ffitarget.h
cp src/x86/ffitarget.h include/ffitarget.h

make

これでやると、-lffiが見つからないって言われる。

devtools::with_envvar(
+   c("FFI_DIR" = "./libffi-3.0.9"),
+   devtools::install()
+ )
Installing Rffi
Skipping 1 packages not available: RAutoGenRunTime
"C:/PROGRA~1/R/R-32~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore CMD INSTALL "C:/Users/yutani/Documents/repo/Rffi"  \
  --library="C:/Users/yutani/Documents/R/win-library/3.2" --install-tests 

* installing *source* package 'Rffi' ...
Copied libffi-5.dll into C:/Users/yutani/Documents/R/win-library/3.2/Rffi/libs//x64
** libs
Warning: this package has a non-empty 'configure.win' file,
so building only the main architecture

gcc -m64 -shared -s -static-libgcc -o Rffi.dll tmp.def addrOf.o converters.o ffi.o struct.o test.o -L./libffi_cyg/.libs -lffi -lm --verbose -Ld:/RCompile/r-compiling/local/local320/lib/x64 -Ld:/RCompile/r-compiling/local/local320/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -lR
Using built-in specs.
COLLECT_GCC=C:\Rtools\gcc-4.6.3\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/rtools/gcc-4.6.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32 --build=x86_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --prefix=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --with-gmp=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpfr=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpc=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --disable-shared --enable-static --enable-targets=all --enable-languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions --enable-fully-dynamic-string --disable-nls --disable-werror --enable-checking=release --disable-win32-registry --disable-rpath --disable-werror CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
Thread model: win32
gcc version 4.6.3 20111208 (prerelease) (GCC) 
COMPILER_PATH=c:/rtools/gcc-4.6.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/;c:/rtools/gcc-4.6.3/bin/../libexec/gcc/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/
LIBRARY_PATH=c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/64/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/lib/../lib64/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../lib64/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/lib/;c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../
COLLECT_GCC_OPTIONS='-m64' '-shared' '-s' '-static-libgcc' '-o' 'Rffi.dll' '-L./libffi_cyg/.libs' '-v' '-Ld:/RCompile/r-compiling/local/local320/lib/x64' '-Ld:/RCompile/r-compiling/local/local320/lib' '-LC:/PROGRA~1/R/R-32~1.2/bin/x64' '-mtune=generic' '-march=x86-64'
 c:/rtools/gcc-4.6.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/collect2.exe --sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o Rffi.dll -s c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/lib/../lib64/dllcrt2.o c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/64/crtbegin.o -L./libffi_cyg/.libs -Ld:/RCompile/r-compiling/local/local320/lib/x64 -Ld:/RCompile/r-compiling/local/local320/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/64 -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/lib/../lib64 -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../lib64 -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3 -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/lib -Lc:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../.. tmp.def addrOf.o converters.o ffi.o struct.o test.o -lffi -lm -lR -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/64/crtend.o
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lffi
collect2: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'Rffi'
* removing 'C:/Users/yutani/Documents/R/win-library/3.2/Rffi'

-m64してるから64bit版が必要?と思って↓のようにやってみると、

cd libffi-3.0.9
./configure CC="/c/Rtools/gcc-4.6.3/bin/gcc.exe -m64" CXX="/c/Rtools/gcc-4.6.3/bin/g++.exe -m64" --build=x86_64-w64-mingw32

# README.winの助言に従う
rm include/ffitarget.h
cp src/x86/ffitarget.h include/ffitarget.h

make

今度は、DLLがない。うむむ。。

$ ls .libs/
libffi.a  libffi.la  libffi.lai  libffi_convenience.a  libffi_convenience.la