Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran build does not add static library directory as include directory #237

Closed
byon opened this issue Aug 23, 2015 · 1 comment
Closed

Comments

@byon
Copy link
Contributor

byon commented Aug 23, 2015

Hello,

I started experimenting with Fortran builds and I tried to create a static library used from the main program. The compilation of main program fails, because it cannot find the mod file(s) of the static library. I assume this is because the compilation command does not define the static library directory as include directory (-I option with gfortran).

(Note that I may be completely wrong in my assumptions, because I am just starting with both Fortran and meson.)

I have the the following files all in the same directory:

  • meson.build
  • main.f95
  • static_hello.f95

meson.build:

project('try-static-library', 'fortran')
static_hello = static_library('static_hello', 'static_hello.f95')
executable('test_exe', 'main.f95', link_with : static_hello)

main.f95

program hello
  use static_hello
  implicit none

  call static_say_hello()
end program hello

static_hello.f95

module static_hello
  implicit none

  private
  public :: static_say_hello

  interface static_say_hello
     module procedure say_hello
  end interface static_say_hello

contains

  subroutine say_hello
    print *, "Hello World!"
  end subroutine say_hello

end module static_hello

Output that shows the error:

> ninja
[3/4] Compiling fortran object test_exe@exe\main.f95.obj
FAILED: gfortran "-pipe" "-Wall" "-g" "-Itest_exe@exe" "-I.." "-I." "-Jtest_exe@exe"  -o test_exe@exe\main.f95.obj -c ..\main.f95
..\main.f95:2.6:

  use static_hello
      1
Fatal Error: Can't open module file 'static_hello.mod' for reading at (1): No such file or directory
[3/4] Static linking library static_hello.lib
ninja: build stopped: subcommand failed.

If I add the "-Istatic_hello@sta" option manually to test_exe@exe\main.f95.obj build rule in build.ninja, the build works. Hmmm... it actually works only "usually". It seems that there should also be some kind of dependency so that the static library module would always get built first. Now the build fails, if the main is built first (which is understandable, because it requires the mod file, and that is produced by the later build). But that may be a separate issue.

I am using meson from the latest master commit (e6a868e), running on Windows 10, and using GNU Fortran (tdm64-1) 4.9.2.

Thanks,

-Marko

@byon
Copy link
Contributor Author

byon commented Aug 23, 2015

Tested out that it works. Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant