Skip to content

Linking error with test-directory submodule and its parent module in separate files #765

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

Closed
rouson opened this issue Oct 2, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@rouson
Copy link
Contributor

rouson commented Oct 2, 2022

Description

fpm test generates a link-time error when a test-directory submodule exists in a file other than the file containing its parent module.

Expected Behaviour

I expected fpm test to build and run the test(s).

Version of fpm

0.6.0

Platform and Architecture

macOS/Intel

Additional Information

To reproduce the error this issue, execute the following in a Linux or MacOS shell:

% fpm new foo
% cat > foo/test/check.f90 
program check
  use foo_m
  implicit none
  call say_something
end program
<Ctrl-D>
% cat > foo/test/foo_m.f90 
module foo_m
  implicit none
  interface
    module subroutine say_something
    end subroutine
  end interface
end module
<Ctrl-D>
% cat foo/test/foo_s.f90 
submodule(foo_m) foo_s
  implicit none
contains
  module procedure say_something
    print *,"something"
  end procedure
end submodule
<Ctrl-D>
% cd foo
% fpm test
 + mkdir -p build/dependencies
foo_m.f90                              done.
foo.f90                                done.
libfoo.a                               done.
main.f90                               done.
check.f90                              done.
foo_s.f90                              done.
foo                                    done.
check                                  failed.
[ 100%]Compiling...
Undefined symbols for architecture x86_64:
  "___foo_m_MOD_say_something", referenced from:
      _MAIN__ in test_check.f90.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
<ERROR> Compilation failed for object " check "
<ERROR>stopping due to failed compilation
STOP 1

When using gfortran or the Intel ifort, the following workaround enables successful execution of fpm test:

echo 'include "foo_s.f90"' >> test/foo_m.f90

With the NAG nagfor compiler, the above workaround fails so the submodule must be in the same file as the module.

@rouson rouson added the bug Something isn't working label Oct 2, 2022
@LKedward
Copy link
Member

LKedward commented Oct 2, 2022

Thanks for reporting Damian @rouson. I believe this was fixed in #743 which will be available in our next release. You can try the bleeding edge version of fpm in the meantime.
(Duplicate of #556.)

@awvwgk awvwgk added the duplicate This issue or pull request already exists label Oct 2, 2022
@rouson
Copy link
Contributor Author

rouson commented Oct 3, 2022

Thanks, @LKedward. Given that it's a duplicate, I'll close this issue.

@rouson rouson closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants