[R] R package with Fortran module on Windows? undefined reference to `__stack_chk_fail'

peter dalgaard pdalgd at gmail.com
Mon Jul 27 19:55:17 CEST 2015


You went through the trouble to chastise a beginner and failed to spot the difference between R-packages and R-package-devel?

(I think R-devel is better for now. R-package-devel is more for people trying to make CRAN happy.)

-pd

PS: The by-hand example suggests that there is a 32/64 bit mixup.

> On 27 Jul 2015, at 17:58 , Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
> 
> You went to all that trouble to find a mailing list to ask your question on and failed to find R-packages or R-devel?
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
>                                      Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> --------------------------------------------------------------------------- 
> Sent from my phone. Please excuse my brevity.
> 
> On July 27, 2015 10:21:51 AM CDT, Ignacio Martinez <ignacio82 at gmail.com> wrote:
>> Hi,
>> 
>> I created a R library that uses a Fortran module. Everything works like
>> a
>> charm on linux.
>> 
>> Now I'm trying to make it work on Windows. I cloned my git repository
>> <https://github.com/ignacio82/MyPi> on a windows computer, and when I
>> press
>> the build and reload button on Rstudio I get these errors:
>> 
>> ==> Rcmd.exe INSTALL --no-multiarch --with-keep.source MyPi
>> * installing to library
>> 'C:/Users/IMartinez/Documents/R/R-3.2.1/library'* installing *source*
>> package 'MyPi' ...** libs
>> gfortran -m64 -shared -s -static-libgcc -o MyPi.dll tmp.def Fpi.o
>> -Ld:/RCompile/r-compiling/local/local320/lib/x64
>> -Ld:/RCompile/r-compiling/local/local320/lib
>> -LC:/Users/IMARTI~1/DOCUME~1/R/R-32~1.1/bin/x64 -lR
>> Fpi.o: In function `__fortranpi_MOD_dboard':
>> Fpi.f90:(.text+0xd7): undefined reference to `__stack_chk_fail'
>> Fpi.o: In function `pi_':
>> Fpi.f90:(.text+0x249): undefined reference to `__stack_chk_fail'
>> collect2: ld returned 1 exit status
>> no DLL was created
>> ERROR: compilation failed for package 'MyPi'* removing
>> 'C:/Users/IMartinez/Documents/R/R-3.2.1/library/MyPi'
>> 
>> Exited with status 1.
>> 
>> 
>> This is  the Fortran code:
>> 
>> 
>> Module Fortranpi
>> IMPLICIT NONE
>> contains
>> subroutine dboard(darts, dartsscore)
>> integer, intent(in)                    :: darts
>> double precision, intent(out)          :: dartsscore
>> double precision                       :: x_coord, y_coord
>> integer                                :: score, n
>> 
>> score = 0
>> do n = 1, darts
>> call random_number(x_coord)
>> call random_number(y_coord)
>> 
>> if ((x_coord**2 + y_coord**2) <= 1.0d0) then
>> score = score + 1
>> end if
>> end do
>> 
>> dartsscore = 4.0d0*score/darts
>> 
>> end subroutine dboard
>> 
>> subroutine pi(avepi, DARTS, ROUNDS) bind(C, name="pi_")
>> use, intrinsic                         :: iso_c_binding, only :
>> c_double, c_int
>> real(c_double), intent(out)            ::  avepi
>> integer(c_int), intent(in)             ::  DARTS, ROUNDS
>> integer                                ::  MASTER, rank, i, n
>> integer, allocatable                   ::  seed(:)
>> double precision                       ::  pi_est, homepi, pirecv,
>> pisum
>> ! we set it to zero in the sequential run
>> rank = 0! initialize the random number generator! we make sure the
>> seed is different for each task
>> call random_seed()
>> call random_seed(size = n)
>> allocate(seed(n))
>> seed = 12 + rank*11
>> call random_seed(put=seed(1:n))
>> deallocate(seed)
>> 
>> avepi = 0
>> do i = 0, ROUNDS-1
>> call dboard(darts, pi_est)
>> ! calculate the average value of pi over all iterations
>> avepi = ((avepi*i) + pi_est)/(i + 1)
>> end do
>> end subroutine pi
>> 
>> end module Fortranpi
>> 
>> 
>> I tried adding <http://i.stack.imgur.com/lC82X.png>
>> -fno-stack-protector
>> -lssp but it did not help.
>> 
>> I also tried doing this "by hand" <http://i.stack.imgur.com/WY4VD.png>
>> and
>> I get these errors:
>> 
>> 
>>> system("R CMD SHLIB -fno-stack-protector -lssp ./src/Fpi.f90")
>> gfortran -m64 -shared -s -static-libgcc -o src/Fpi.dll tmp.def
>> ./src/Fpi.o -fno-stack-protector -lssp
>> -Ld:/RCompile/r-compiling/local/local320/lib/x64
>> -Ld:/RCompile/r-compiling/local/local320/lib
>> -LC:/Users/IMARTI~1/DOCUME~1/R/R-32~1.1/bin/x64 -lR>
>> dyn.load("./src/Fpi.dll")
>> Error in inDL(x, as.logical(local), as.logical(now), ...) :
>> unable to load shared object
>> 'C:/Users/IMartinez/Projects/MyPi/./src/Fpi.dll':
>> LoadLibrary failure:  %1 is not a valid Win32 application.
>> 'C:/Users/IMartinez/Projects/MyPi/./src/Fpi.dll':
>> LoadLibrary failure:  %1 is not a valid Win32 application.
>> 
>> 
>> Thanks for the help!
>> 
>> 
>> Ignacio
>> 
>> 
>> PS: I posted this question in stackoverflow with no luck.
>> <http://stackoverflow.com/questions/31638934/r-package-with-fortran-module-on-windows-undefined-reference-to-stack-chk-fa>
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list