Fortran 90 compiling issue: undefined reference to

后端 未结 1 568
自闭症患者
自闭症患者 2020-12-16 01:51

I\'m having trouble trying to compile a simple fortran program which uses a module in the same directory. I have 2 files: test1.f90 which contains the program and modtest.f9

相关标签:
1条回答
  • 2020-12-16 02:18

    What you're doing is not telling the linker where reference module modtest is so that the your code can use its 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.

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