-1

I have read this question: How do you USE Fortran 90 module data But I could not solve my problem.

I get error LNK2019: unresolved external symbol when I try to use a variable which is declared in another module.

For background information: I am a beginner in Fortran and am working in a project someone else has created. I am using an Intel fortran composer and visual studio. I do not know for sure if I understand the use of public and private module data properly.

The problem is whenever I try to use the variable BodySystem in another module, it doesn't work and I get the error that there is an unresolved external symbol.

Am I using the public and private parts incorrect or am I missing something else?

Edit: I changed the code into a compilable snippet

Edit2: Deleted the code, since that was not the problem. IanH gave me the right answer as the object file was out of date.

The exact error message I get is:

Error 2 fatal error LNK1120: 1 unresolved externals Debug\HmSlam.exe
Error 1 error LNK2019: unresolved external symbol _COORDINATESSYSTEM_M_mp_BODYSYSTEM referenced in function _MAIN__ HmSlam.obj

where HmSlam is the main program and coordinatessystem_m is the module where the variable bodysystem is declared.

Community
  • 1
  • 1
BarendB
  • 71
  • 6
  • 1
    Can you post a compilable snippet which is large enough to illustrate the problem but no larger. And can you post the exact error message. The trouble with trying to fix pseudocode is that fixes tend to produce the response *yes, what I posted was only pseudocode the trouble is that in my real code ...* – High Performance Mark Sep 12 '14 at 12:33
  • 2
    I suspect that you are still posting misleading 'code'; I don't think that putting the `public` specifiers where you have it in the module is correct. Try putting it on a line just after the `private` specifier. Also, I think that the `contains` statement should probably follow the `end type` rather than preceding it. – High Performance Mark Sep 12 '14 at 12:55
  • I edited it again, I find it a bit difficult to determine what is and what is not that important. So now I included the initialize subroutine as an example of a subroutine (which is also the first thing I would want to do if I am able call the bodysystem). – BarendB Sep 12 '14 at 13:08
  • You want to `call` a variable? – Alexander Vogt Sep 12 '14 at 13:17
  • 1
    Do you mix up Coordinate*s*System (the name of the module) and CoordinateSystem (in the `use` statement)? – Stefan Sep 12 '14 at 13:22
  • Very sharp, however that was a typing error not in my source file in the use statement. I feel like a hopeless beginner in asking questions here but I have to start somewhere. – BarendB Sep 12 '14 at 13:41
  • I would suggest starting to construct some code that is actually compilable **and shows the same error**. Usually I already find my mistakes when constructing such an example. – Alexander Vogt Sep 12 '14 at 13:45
  • It is very hard to help you with how your question (in the current revision) written, and it does not help much that you reveal information piece-by-piece, subtly changing the question every time. Please prepare your questions better. I'm voting to close this question. – Alexander Vogt Sep 12 '14 at 13:48
  • I tried to shorten the question into the relevant part as IanH solved my problem. – BarendB Sep 12 '14 at 14:11

1 Answers1

0

The "mangling" of the missing symbol in the linker error message tells you that the compiler knows that the name BODYSYSTEM comes from the module COORDINATESSYSTEM_M, otherwise it wouldn't have been able to mangle the module name and the symbol name together in the way that it has (compilers will have different name mangling conventions).

That tells you that the problem is probably not with the compiling of your code - something is going wrong in the linking stage.

I suspect you are providing out-of-date object files to the linker, or you are not providing the relevant object file at all.

(While we are here:

  • The use of type bound procedures means that this isn't Fortran 90 - it is at least Fortran 2003. Welcome to the 21st century.

  • You don't have a private and public "part" to your source - what you have are private and public statements. The PRIVATE keyword on its own in a statement indicates that the default accessibility for the module is private - i.e. by default the things defined or declared in the module won't be made available in places where the module is USE'd. Without such a private statement the default for a module is public. The PUBLIC keyword followed by a list of identifiers then specifies that those identifiers are public (contrary to the default set by private). The general positioning and number of the private and public statements isn't significant, as long as they appear in the specification part of the module, after any use and implicit statements.

  • naming an identifier in the ONLY specifier of a USE statement doesn't "call" anything, it just says "only this symbol (along with any others listed in the specifier) are available from this module for use in the following scope".

IanH
  • 21,026
  • 2
  • 37
  • 59