linker - How to reuse Fortran modules without copying source or creating libraries -


i'm having trouble understanding if/how share code among several fortran projects without building libraries or duplicating source code.

i using eclipse/photran intel compiler (ifort) on linux system, believe i'm having bigger conceptual problem modules specific tools.

here's simple example: in ~/workspace/cow have source directory (src) containing cow.f90 (the program) , 2 modules m_graze , m_moo in m_graze.f90 , m_moo.f90, respectively. project builds , links create executable 'cow'. executable , modules (m_graze.mod , m_moo.mod) stored in ~/workspace/cow/debug , object files stored under ~/workspace/cow/debug/src

later, create ~/workplace/sheep , have src/sheep.f90 program , src/m_baa.f90 module m_baa. want 'use m_graze, only: ruminate' in sheep.f90 access ruminate() subroutine. copy m_graze.f90 lead code getting out of sync , doesn't take account dependencies m_graze might have. these reasons, i'd rather leave m_graze in cow project , compile , link sheep.f90 against it.

if try compile sheep project, i'll error like:

error #7002: error in opening compiled module file.  check include paths.   [m_graze] 

under properties:project references sheep, can select cow project. under properties:fortran build:settings:intel compiler:preprocessor can add ~/workspace/cow/debug (location of module files) list of include directories compiler finds cow modules , compiles sheep.f90. linker dies like:

building target: sheep invoking: intel(r) fortran linker ifort -l/home/me/workspace/cow/debug -o "sheep"  ./src/sheep.o ./src/sheep.o: in function `sheep': /home/me/workspace/sheep/src/sheep.f90:11: undefined reference `m_graze_mp_ruminate_' 

this solved adding libraries , library paths linker settings except there no appropriate libraries link (this fortran, not c.)

the cow project capable of compiling , linking cow.f90, m_graze.f90 , m_moo.f90 executable. yet while sheep project can compile sheep.f90 , m_baa.f90 , can find module m_graze.mod, can't seem find symbols m_graze though requisite information present on system so.

it seem easy matter of configuration linker portion of ifort find missing pieces , put them have no idea magic words need entered in photran ui make happen.

i confess utter lack of interest , competence in c , c build process , i'd rather avoid diversion of creating libraries (.a or .so) unless that's way make work.

ultimately, i'm looking pure fortran solution problem can keep single copy of source code , don't have manually maintain pile of custom makefiles.

so can done?

apologies if has been documented somewhere; google showing me simple build examples, how create modules, , how link existing libraries. there don't seem (m)any examples of code reuse modules don't involve duplicating source code.


edit

as respondents have pointed out, .mod files necessary not sufficient; either object code (in form of m_graze.o) or static or shared libraries must specified during linking phase. .mod files describe interface object code/library both necessary build final executable.

for oversimplified toy problem such this, that's sufficient answer question posed.

in larger project more complex dependencies (in case, 80+kloc of f90 linking mkl version of lapack95), ide or toolchain may lack sufficient automatic or user-interface facilities make sharing single canonical set of source files viable strategy. choice seems between risking duplicate source files getting out of sync, giving many of benefits of ide (i.e. avoiding manual creation of make/cmake/scons files), or, in likelihood, both. while revision control system , code organization can help, it's clear sharing single canonical set of source files among projects far easy given current state of eclipse.

some background suspect know: typically (including ifort) compiling source code fortran module results in 2 outputs - "mod" file contains description of fortran entities module defines compiler needs find whenever sees use statement module, , object code linker implements procedures , variable storage, etc., module defines.

your first error (the 1 solved) because compiler couldn't find mod file.

the second error because linker hasn't been told object code implements stuff in source file module. i'm not eclipse user means, brute force way of specifying add object file (xxxxx/debug/m_graze.o) additional linker option (fortran build > settings, under intel fortran linker > command line). (other tool chains have explicit "additional object file" properties link stage - there may better way of doing intel chain.)

for more involved examples typically create library out of shared code. that's not c specific, fortran aspect libraries archive of object code needs provided alongside mod files fortran compiler generates.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -