Fortran Error Undefined Reference To Subroutine
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring fortran undefined reference to main developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask gfortran collect2: error: ld returned 1 exit status Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join undefined reference to fortran 77 them; it only takes a minute: Sign up Error in fortran, undefined reference to subroutine up vote 0 down vote favorite I am writing a subroutine and main function to call it, but getting error as undefined reference to fortran undefined reference to mod ___. I found one reason: When I save the main and subroutine in the same file, compile and run that file, everything runs perfectly. However, when I save them into different .f90 files and try to run the main file, I get error. Is there any way I can make subroutine into a separate file and call into main calling program? I got confused with another place - in the main program at !------ERROR------ place. I referred to Automatic
Fortran Use Module
width integer descriptor in fortran 90 I can use I0 as automatic width display indicator. But when I used the same, there is run time error expected integer but got character. Any idea about this? ! saved as sub_program.f90 file SUBROUTINE sub_program (v1,v2,ctr) IMPLICIT NONE INTEGER, INTENT(IN) :: ctr INTEGER, INTENT (OUT) :: v1,v2 SELECT CASE (ctr) CASE (1) v1=1 v2=0 CASE (2) v1=0 v2=1 END SELECT RETURN END SUBROUTINE ! main calling program, saved as caller.f90 PROGRAM caller IMPLICIT NONE INTEGER :: v1,v2,ctr DO ctr = 1,2,1 CALL sub_program (v1,v2,ctr) WRITE (*,100) 'STEP = ',ctr,'V1 = ',v1,'V2 = ',v2 !------ERROR------ 100 FORMAT (I0) END DO END PROGRAM Thanks! fortran fortran90 gfortran share|improve this question asked Apr 15 '15 at 0:45 user3705273 589 3 show the command used to compile –agentp Apr 15 '15 at 0:56 Please revisit the FORMAT statement, you try to write out 3 character strings and 3 integers with just one I0 –albert Apr 15 '15 at 7:55 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote What is your compile command? For me, this compiles and runs normally gfortran caller.f90 foo.f90 && ./a.out I0 is an integer indicator, but some items following your WRITE statement are character strings. You can try, for example, 100 FORMAT (3(A, I0, 1X)) where 1X refers to a space. As a note, if formatting is
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Fortran Use Statement
the company Business Learn more about hiring developers or posting ads with us Stack Overflow compile fortran Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 fortran interface million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linking fortran module: “undefined reference” up vote 2 down vote favorite 1 I'm trying to write some functions/subroutines in http://stackoverflow.com/questions/29639760/error-in-fortran-undefined-reference-to-subroutine a module that call another function in the same module and running into linker errors. A toy example displaying the same behavior: !in test.f module m1 implicit none contains real function mult(a, b) real :: a real :: b mult = a * b return end function mult real function sq(a) real :: a, mult sq = mult(a, a) return end function sq end module m1 program main use m1 write(*,*) sq(2.0) http://stackoverflow.com/questions/11512897/linking-fortran-module-undefined-reference end program When I try to compile this, I run into trouble: [christopher@archlinux metropolis]$ gfortran -ffree-form test.f /tmp/ccpzdTLE.o: In function `__m1_MOD_sq': test.f:(.text+0x20): undefined reference to `mult_' collect2: error: ld returned 1 exit status On the other hand, compiling only (gfortran -c -ffree-form test.f -Wall) runs with no complaint. Now this looks for all the world like a compiler error---in the module it comes up with a reference to mult_ when it really ought to com up with __m1_MOD_sq---but I have a very hard time believing that this is a compiler bug rather than me doing something stupid. DDG didn't turn up anything useful. Most of the similar problems ocurred in splitting the module off from one main file. In those cases, things worked when the module was in the same file as the program, which is not the case here. I looked at a number of pages on modules in Fortran and didn't see anything relevant. Can anyone point me to appropriate documentation or, better yet, explain what's going on and how I can fix it? module linker fortran gfortran share|improve this question asked Jul 16 '12 at 21:32 Christopher White 7516 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted You don't need to declare function mult in functi
a fortran90 program structure which is somewhat like shown below, but when compiling I always get this compiler message: /home/chwi/Programme/tools/test/lib/main.o: In function `MAIN_': /home/chwi/Programme/tools/test/lib/main.o(.text+0x789): undefined reference to `module1_do_something_' What do I have to do to get rid of this undefines reference? Thanks Chris Windmeier !------------------------------------------- PROGRAM MAIN http://computer-programming-forum.com/49-fortran/bd7e07c689e1e759.htm USE MODULE1 . . . . CALL do_something() . . . http://askubuntu.com/questions/299843/undefined-reference-when-using-gfortran-to-compile-fortran-77-code . END MAIN MODULE MODULE1 CONTAINS SUBROUTINE do_something () . . . . undefined reference END SUBROUTINE do_something END MODULE MODULE1 !------------------------------------------- Sat, 17 Dec 2005 21:02:17 GMT Dan Nagl#2 / 8 undefined reference to subroutine in module Hello, It may be nothing more than putting the module ahead of the program in your source file. The standard says the module has to "be available" when the program is compiled. At least, it wouldn't hurt to try the simple fix first. :-) HTH -- Cheers! Dan Nagle Purple Sage Computing Solutions, Inc. Quote:>Hello Everybody! >I want undefined reference to to use a Fortran90 program structure which is somewhat like >shown below, but when compiling I always get this compiler message: >/home/chwi/Programme/tools/test/lib/main.o: In function `MAIN_': >/home/chwi/Programme/tools/test/lib/main.o(.text+0x789): undefined >reference to `module1_do_something_' >What do I have to do to get rid of this undefines reference? >Thanks >Chris Windmeier >!------------------------------------------- >PROGRAM MAIN > USE MODULE1 > . . > . . > CALL do_something() > . . > . . >END MAIN >MODULE MODULE1 > CONTAINS > SUBROUTINE do_something () > . . > . . > END SUBROUTINE do_something >END MODULE MODULE1 >!------------------------------------------- Sat, 17 Dec 2005 21:27:01 GMT dimitr#3 / 8 undefined reference to subroutine in module Hi Dan The Module is already located within a seperate file which is compiled before the main part is compiled. So that doesn't do it Quote:> Hello, > It may be nothing more than putting the module ahead of the program > in your source file. The standard says the module has > to "be available" when the program is compiled. > At least, it wouldn't hurt to try the simple fix first. :-) > HTH > -- > Cheers! > Dan Nagle > Purple Sage Computing Solutions, Inc. > >Hello
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Undefined reference when using gfortran to compile fortran 77 code [closed] up vote 0 down vote favorite I have an old fortran 77 code, which compiles well on Sun workstation. However, there are errors when I try to compile it using gfortran on Ubuntu (64 bits): $ gfortran -Wall -g -Jobj/Debug/ -ffixed-form -lc -lm -lg2c -c main.for -o obj/Debug/main.o The following is the information given by gfortran 3015 main.for|32994| undefined reference to `qextd_' 3016 main.for|33000| undefined reference to `qextd_' 3017 main.for|33000| undefined reference to `qmod_' 3018 main.for|33000| undefined reference to `dbleq_' 3019 main.for|33015| undefined reference to `dbleq_' 3020 main.for|33015| undefined reference to `dbleq_' How can I solve this problem? Thanks Jerry,Seth,and Arjen Markus(personal communication) I believe we have already found out the problem,those functions(qmod,qextd,qfloat,etc) are related to quad-precision expressions. It maybe succeeds in compiling and linking if following your suggestions to use real type instead of quad-precision. But in order to have reliable result and precision I still feel like using quad-precision. The problem is that I am not sure whether it is suitable for old fortran 77 code to use quad-precision with gfortran or f77 on ubuntu. Here is one answer I googled: http://stackoverflow.com/questions/11399178/quad-precision-in-gfortran compiling fortran share|improve this question edited Sep 17 at 2:06 Seth♦ 22.8k1889140 asked May 25 '13 at 10:32 user161614 1113 closed as unclear what you're asking by Eric Carvalho, edwinksl, Zanna, Anwar, David Foerster Sep 20 at 9:35 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactl