Linking to modules folder gives undefined reference

后端 未结 2 1721
春和景丽
春和景丽 2021-01-22 18:57

if I understood the manual correctly it should work to creat a file containing a fortran module in a folder, say /path/mods/test_mod.f90 i.e. :

module test_mod
i         


        
相关标签:
2条回答
  • 2021-01-22 19:00

    You need to include the .o file as well. That is, you should compile this as

    gfortran -I/path/to/mods -o test_prog test_prog.f90 mods/test_mod.o
    

    This worked and ran for me.

    0 讨论(0)
  • 2021-01-22 19:23

    This

    gfortran -c test_mod.f90
    

    should produce two files: test_mod.mod and test_mod.o. Your other compilation statement

    gfortran -I/path/mods -o test_prog test_prog.f90
    

    correctly specifies the location in which to look for the .mod file but omits the .o file. The .mod file is a bit like a compiler-generated header file, it is used for compilation of any program units which use-associate the module, but the object file is needed for linking.

    The simplest (I think) fix is to write

    gfortran -o test_prog -I/path/mods /path/mods/test_mod.o test_prog.f90
    

    but you may want to fiddle around with that.

    0 讨论(0)
提交回复
热议问题