Hi, I am trying to compile a FORTRAN program to call from R under Windows 7 but I am having problem in the compiling step. To demonstrate this is the program testit.f: ------------------------------------------ subroutine TESTIT(x,n,m) dimension x(n) do 10 i=1,n 10 x(i)=x(i)**m end -------------------------------------------- When I compile it with gfortran I get the following error: -------------------------------------------------- c:\MinGW\programs>gfortran testit.f -o testit.o c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o):main.c:(.tex t+0xd2): undefined reference to `WinMain@16' collect2: ld returned 1 exit status. ---------------------------------------------------- I should add that a program like the following hello.f compiles with no problem. ------------------------------------------ READ (*, *) YOURNAME WRITE (*, 200) YOURNAME 200 FORMAT(//,' Hello ',A/) STOP END ------------------------------------------ I realize that this is not directly a question about R but I guess there are some people here who have compiled FORTRAN programs under Windows 7 to call from R. I appreciate any help to fix the problem. /Mikael [[alternative HTML version deleted]]
You are compiling a subroutine not a program and you compile line should read: gfortran testit.f -c testit.o You then reference that object code testit.o in your final loading stage after compiling other routiens and the main program. -- Clint Bowman INTERNET: clint at ecy.wa.gov Air Quality Modeler INTERNET: clint at math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Thu, 5 May 2011, Mikael Anderson wrote:> Hi, > > I am trying to compile a FORTRAN program to call from R under Windows 7 but > I am having problem in the compiling step. To demonstrate this is the > program testit.f: > > ------------------------------------------ > subroutine TESTIT(x,n,m) > dimension x(n) > do 10 i=1,n > 10 x(i)=x(i)**m > end > -------------------------------------------- > > When I compile it with gfortran I get the following error: > > -------------------------------------------------- > c:\MinGW\programs>gfortran testit.f -o testit.o > c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o):main.c:(.tex > t+0xd2): undefined reference to `WinMain at 16' > collect2: ld returned 1 exit status. > ---------------------------------------------------- > > I should add that a program like the following hello.f compiles with no > problem. > > ------------------------------------------ > READ (*, *) YOURNAME > WRITE (*, 200) YOURNAME > 200 FORMAT(//,' Hello ',A/) > STOP > END > ------------------------------------------ > > I realize that this is not directly a question about R but I guess there are > some people here who have compiled FORTRAN programs under Windows 7 to call > from R. I appreciate any help to fix the problem. > > /Mikael > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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. >
Mikael Anderson wrote:> > Hi, > > I am trying to compile a FORTRAN program to call from R under Windows 7 > but > I am having problem in the compiling step. To demonstrate this is the > program testit.f: > > ------------------------------------------ > subroutine TESTIT(x,n,m) > dimension x(n) > do 10 i=1,n > 10 x(i)=x(i)**m > end > -------------------------------------------- > >In addition to the previous remarks, you would do yourself a favour by utilizing the implicit-none option of gfortran. That will force you to declare every variable (and its type) which will avoid many nasty bugs. In your case: x is a REAL single precision but with R you will preferably need double precision. So I would advise you to use gfortran -fimplicit-none ...... Berend -- View this message in context: http://r.789695.n4.nabble.com/Compiling-a-FORTRAN-program-under-Windows-7-tp3498663p3498839.html Sent from the R help mailing list archive at Nabble.com.