Fortran Error Undefined Reference To
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 fortran undefined reference to main hiring 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.
Undefined Reference To Fortran 77
Join them; it only takes a minute: Sign up Fortran 90 compiling issue: undefined reference to
Fortran Undefined Reference To Mod
the same directory. I have 2 files: test1.f90 which contains the program and modtest.f90 which contains the module. This is test1.f90: program test use modtest implicit none print*,a end program test This is modtest.f90: module modtest implicit none save integer :: a = 1 end module modtest Both files are in the same directory. I compile modtest.f90 and test.f90 like this: gfortran -c modtest.f90 gfortran -o test1 test1.f90 But then I get this error: /tmp/cckqu8c3.o: In function `MAIN__': test1.f90:(.text+0x50): fortran use module undefined reference to `__modtest_MOD_a' collect2: ld returned 1 exit status Is there something I'm missing? Thanks for the help module compiler-errors fortran fortran90 share|improve this question asked Oct 11 '10 at 9:01 Eddy 1,838123757 3 programming questions... this is what So is for. Ask if you don't know. –Preet Sangha Oct 11 '10 at 18:42 Or: gfortran modtest.f90 test1.f90 -o test1 –M. S. B. Jun 20 '13 at 5:44 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted What you're doing is not telling the linker where reference module modtest is so that the your code can use it's contents. This should work: gfortran -o test1 test1.f90 modtest.o Some context: the -o option tells the compiler to put the output of the full build (compile + link) into a program called test1. Then we supply a file that we are to compile (test1.f90). Finally we are telling the compiler to consider a file that contains the compiled output of another build (modtest.o) and to link this to the compiled output of test1.f90, and use the contents of modtest.o when trying to sort out references within the test1.f90 that reference the module modtest (in the statement use modtest in the source code). So the statement says: Please compile and subsequently link test1.f90 to modtest.o, and produce a file called test1 as the final output. s
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 fortran use statement Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation compile fortran Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like fortran interface 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 a module that call another http://stackoverflow.com/questions/3904814/fortran-90-compiling-issue-undefined-reference-to-modulename 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) end program When I try to compile this, http://stackoverflow.com/questions/11512897/linking-fortran-module-undefined-reference 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 function sq, i.e., there is no need for "real :: mult". sq already "knows" about mult s
LearningModern CodeNetworkingOpen SourceStorageToolsDeveloper TypeEmbedded SystemsGame DevMediaTechnical, Enterprise, HPCWebOSAll ToolsAndroid*HTML5Linux*OS X*Windows*ResourcesCode SamplesContact SupportDocumentationFree SoftwareIntel Registration CenterProduct ForumsSDKsResourcesPartner with IntelAcademic ProgramPartner SpotlightBlack Belt DeveloperDeveloper MeshInnovator ProgramSuccess StoriesLearnBlogBusiness https://software.intel.com/en-us/articles/error-undefined-reference-to-main TipsEventsVideosSupportContact SupportDeveloper EvangelistsFAQsForums Search form Search Error: undefined reference to 'MAIN__' Added December 27, 2008 Translating...TranslateChinese SimplifiedChinese TraditionalEnglishFrenchGermanItalianPortugueseRussianSpanishTurkish This is a computer translation http://www.unidata.ucar.edu/support/help/MailArchives/netcdf/msg12375.html of the original content. It is provided for general information only and should not be relied upon as complete or accurate. Share undefined reference Tweet Share Problem When building an application, you get the error "undefined reference to 'MAIN__'" Environment Linux* and Mac OS* X Root Cause : You have attempted to link an application that does not contain a Fortran main program. Resolution If you are compiling sources separately undefined reference to to be linked later, add the -c option to the ifort command to tell the ifort driver not to invoke the linker. If you are building a mixed-language application whose main program is not written in Fortran, use the -nofor-main option to specify this. For more information, please refer to the Compiler Options section of the Intel Fortran Compiler User and Reference Guides. For more complete information about compiler optimizations, see our Optimization Notice. Categories: Intel® Fortran Compiler Fortran Linux* Apple OS X* ForumsIntel® Fortran Compiler Add a Comment Top (For technical discussions visit our developer forums. For site or software product issues contact support.) Please sign in to add a comment. Not a member? Join today Support Terms of Use *Trademarks Privacy Cookies Publications Intel® Developer Zone Newsletter Intel® Parallel Universe Magazi
Status Archived Data Access Data Management Resource Center Software Display & Analysis AWIPS II GEMPAK IDV McIDAS Data Access & Management LDM LDM-McIDAS Decoders NetCDF NetCDF Java Rosetta THREDDS Data Server UDUNITS Deprecated Software GARP NetCDF Decoders NetCDF Perl Downloads Display & Analysis AWIPS II GEMPAK IDV McIDAS Data Access & Management LDM LDM-McIDAS Decoders NetCDF & NetCDF Java THREDDS Data Server UDUNITS Deprecated Software GARP NetCDF Decoders NetCDF Perl Terms & Conditions Provision of Software Support Support Resources Documentation Training Tutorials Mailing Lists Support Archives Submit a Request Suggested Support Process Email-Based Web-Based Terms & Conditions Obtaining Support Register as a User Community Outreach & Opportunities News from Unidata Unidata Events News from the Community Job Opportunities DeSouza Award Equipment Awards Summer Internships We Are Community Driven Participating Institutions Collaborations Education Resources Software & Data in Use How to Participate Acknowledging Unidata Governance Unidata's Governance Model Strategic Advisory Committee Users Committee Publications & Resources Bibliography Glossary of Terms Projects Current Projects ACADIS Case Studies Common Data Model CONDUIT Data Management Resource Center GALEON GEON IDV Google Africa Initiative GRIDSPEC HYDRO-NEXRAD Internet Data Distribution LibCF McIDAS-V Data Intercomparisons Next-Generation LDM OPULS OWCS Python RAMADDA in the Unidata Community Teaching Resources Project Archive News News from Unidata News from Unidata Unidata Events Unidata Developer's Blog News from the Community News From the Community Community Jobs News Archives Events Summer/Fall 2016 Software Training Workshop Unidata Events Calendar of Events Seminar Series Conferences & Meetings Unidata Workshops Training Workshops Triennial Workshops Regional Workshops Data Workshops About Us The Unidata Program Overview of Unidata Highlights & Reports Unidata Brochure Unidata Director's Page Our Organizat