[R] problem building an R package under Windows XP with calls to NAG C routines

Duncan Murdoch murdoch at stats.uwo.ca
Fri Oct 29 04:06:52 CEST 2004


The problem is that MSVC libraries are not compatible with gcc.  The
gcc linker doesn't know what to do with them, they're in a different
format than it expects.

To do static linking, you'll need to use MSVC to compile and link your
DLL in the package.  This means setting up a Makefile.win so that MSVC
gets called instead of gcc.  There's some info on this in the
README.packages file, but it's incomplete, because none of the core
developers use MSVC.   If you want to add to it, send me the patches.

Alternatively, just install the package using your "Hello, world" DLL,
then compile the real DLL using MSVC and put it into the libs
subdirectory where your package was installed.

Note that if you want to put your package on CRAN, you'll have to be
able to build it without proprietary tools.

Duncan Murdoch

On Thu, 28 Oct 2004 18:15:46 -0700, "Romain Neugebauer"
<romainn at hotmail.com> wrote:

>Hello all,
>
>I was able to create R packages under windows XP in the past using the 
>dynamic NAG C library for windows XP (Mark 6).
>
>Recently, I changed computers and I am now using the static NAG C library 
>for windows XP (Mark 7) to create a simple R package (called "test") which 
>simply returns random numbers simulated using repetitive calls to a NAG C 
>routine (uniform random generator). I use R Version 2.0.0. and installed all 
>the tools needed to build R packages as described in 
>http://www.murdochsutherland.com/Rtools/ and readme.packages.
>
>I was able to successfully execute the C program that is part of this 
>package when compiling it using Microsoft visual studio. However, when I now 
>try to create the R package with the command "Rcmd INSTALL test" I obtain 
>the following:
>
>C:\Rdevelop>Rcmd INSTALL test
>
>
>---------- Making package test ------------
>  adding build stamp to DESCRIPTION
>  making DLL ...
>making test.d from test.c
>gcc   -Ic:/R/rw2000/include -Wall -O2 -I"C:\Program Files\Numerical 
>Algorithms Group\CLW3207DA\include"  -c test.c -o test.o
>ar cr test.a test.o
>ranlib test.a
>windres --include-dir c:/R/rw2000/include  -i test_res.rc -o test_res.o
>gcc  --shared -s  -o test.dll test.def test.a test_res.o  
>-Lc:/R/rw2000/src/gnuwin32 -L"C:\Program Files\Microsoft Visual 
>Studio\VC98\Lib" -L"C:\Program Files\
>Numerical Algorithms Group\CLW3207DA" -L"C:\Program Files\Numerical 
>Algorithms Group\CLW3207DA\mkl\lib" -lLIBCMT -lnagcsmt-mkl -lmkl_s -lmkl_def 
>-lmkl_lapack
>-lADVAPI32 -lNETAPI32  -lg2c -lR
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>/mingw/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to 
>`WinMain at 16'
>make[3]: *** [test.dll] Error 1
>make[2]: *** [srcDynlib] Error 2
>make[1]: *** [all] Error 2
>make: *** [pkg-test] Error 2
>*** Installation of test failed ***
>
>Removing 'C:/R/rw2000/library/test'
>Restoring previous 'C:/R/rw2000/library/test'
>
>
>Interestingly enough, if I remove the calls to the NAG C routine in the C 
>program AND if I remove the gcc flag "-lLIBCMT", the R package can be 
>created successfully and I can use the package in R (it will simply print a 
>"hello the world" line). I obtain:
>
>C:\Rdevelop>Rcmd INSTALL test
>
>
>---------- Making package test ------------
>  adding build stamp to DESCRIPTION
>  making DLL ...
>gcc  --shared -s  -o test.dll test.def test.a test_res.o  
>-Lc:/R/rw2000/src/gnuwin32 -L"C:\Program Files\Microsoft Visual 
>Studio\VC98\Lib" -L"C:\Program Files\
>Numerical Algorithms Group\CLW3207DA" -L"C:\Program Files\Numerical 
>Algorithms Group\CLW3207DA\mkl\lib"  -lnagcsmt-mkl -lmkl_s -lmkl_def 
>-lmkl_lapack  -lADVAPI
>32 -lNETAPI32  -lg2c -lR
>  ... DLL made
>  installing DLL
>  installing R files
>  installing data files
>  installing man source files
>  installing indices
>  not zipping data
>  installing help
> >>> Building/Updating help pages for package 'test'
>     Formats: text html latex example chm
>  f                                 text    html    latex   example
>  adding MD5 sums
>
>* DONE (test)
>
>If I add the flag "-lLIBCMT" (and the C program still does not call any NAG 
>routine) I get the following:
>
>C:\Rdevelop>Rcmd INSTALL test
>
>
>---------- Making package test ------------
>  adding build stamp to DESCRIPTION
>  making DLL ...
>making test.d from test.c
>gcc   -Ic:/R/rw2000/include -Wall -O2 -I"C:\Program Files\Numerical 
>Algorithms Group\CLW3207DA\include"  -c test.c -o test.o
>test.c: In function `test':
>test.c:7: warning: unused variable `i'
>ar cr test.a test.o
>ranlib test.a
>gcc  --shared -s  -o test.dll test.def test.a test_res.o  
>-Lc:/R/rw2000/src/gnuwin32 -L"C:\Program Files\Microsoft Visual 
>Studio\VC98\Lib" -L"C:\Program Files\
>Numerical Algorithms Group\CLW3207DA" -L"C:\Program Files\Numerical 
>Algorithms Group\CLW3207DA\mkl\lib" -lLIBCMT -lnagcsmt-mkl -lmkl_s -lmkl_def 
>-lmkl_lapack
>-lADVAPI32 -lNETAPI32  -lg2c -lR
>Warning: .drectve `%.*s' unrecognized
>Warning: .drectve `%.*s' unrecognized
>/mingw/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to 
>`WinMain at 16'
>make[3]: *** [test.dll] Error 1
>make[2]: *** [srcDynlib] Error 2
>make[1]: *** [all] Error 2
>make: *** [pkg-test] Error 2
>*** Installation of test failed ***
>
>Removing 'C:/R/rw2000/library/test'
>Restoring previous 'C:/R/rw2000/library/test'
>
>So it appears that the problem is not related to the calls to the NAG C 
>routines but to the library "LIBCMT" which is required when using the NAG 
>routines.
>I contacted the NAG people who recommended to check the version of the 
>binutils and gcc from Mingw. I use gcc version 3.3.1 and I update the 
>binutils from
>http://www.mingw.org/download.shtml using 
>binutils-2.13.90-20021006-2.tar.gz.
>
>Any help would be greatly appreciated.
>Note that I am able to build the same R package with calls to NAG routines 
>under linux with the static NAG C library for linux.
>
>Thank you,
>
>Romain
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list