Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Comunicados
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Using module (.mod) files

krishnabc
Principiante
6.951 Visualizações
I wanted to use the .mod files to other projects which are created ina project . I followed the steps described in this link(examples too, actually). However, Igot linking errors (error LNK2019: unresolved external symbol...). I also tried to put the .mod files in another directory using /module:path option andlocating itwith /I compileroption in another project, but no avail. Surprisingly, I was successful to compile and run the second project atonce using the above approach.I think it was successful when both .mod and .obj filesof the moduleswere there. Later, I didn't find .obj files, andthat could be reason ofthe error LNK2019, I think.

Would appreciate your suggestions.
0 Kudos
28 Respostas
mecej4
Colaborador honorário III
5.711 Visualizações
When a source file containing module declaration is compiled, a .MOD file and a .OBJ file are produced. The .MOD files are used by the compiler when compiling other subprograms that USE the modules. At link time, the .OBJ files produced earlier must be included. If some of the .MOD files and .OBJ files are from another project, you have to tell the compiler where to find the .MOD files (during compilation) and you have to tell the linker which .OBJ files to link.

Merely including .MOD files in the project does not tell the linker to use the corresponding .OBJ files; it complicates matters that the count and names of .MOD files and .OBJ files may not match.
krishnabc
Principiante
5.711 Visualizações
Thank you mecej4. I understand it,butthe .OBJ files from modules are missing from project ONE now ( I don't see them). Before, I can see both the generated .MOD and .OBJ files (of module) in project ONE.The project ONE still compiles and runs fine; project TWO fails.I also tried to linkthe project TWO directly with DEBUG/RELEASE directory of project ONE and removing the /module:path option from project ONE. There are only .MOD files in both the DEBUG/RELEASE folder of project ONEthat I can see now.
krishnabc
Principiante
5.711 Visualizações
In another case, there are both .MOD and .OBJ files from modules in project ONE, yet the second project in another directory shows LNK2019 errors upon using USE modules assocation. One thing I didnot understand is that the second project compiled/linked fine for a few initial runs. Afer I made some changes in the code, CLEANed the BUILD and REBUILD, the LNK2019 errors started to appear.
Steven_L_Intel1
Funcionário
5.711 Visualizações
Did you change the output or intermediate directory of one project to be that of the other? If so, don't do that and put it back.

My recommended way of using modules from a separate project is to make the "module" project a static library (or DLL) and then make the library project a dependent of the executable project. In version 11.1 and earlier you would also need to add the output directory of the library project to the "Additional Include Paths" of the parent, but as of version 12 that is done automatically.
krishnabc
Principiante
5.711 Visualizações
Dear Steve,

No, I didn't touch the output or intermediate directory. However, I tried both options with module path to a new separate folder (NOT to the second project) and without specifying it in the first project. In the second project, I had used "Additional Include Directories" to the directory where .MOD files of the first project exist.

That means, would you say that if I needed to pass a part of the source codeto the third person, but I do not want to disclose the source code to him/her, the recommended way is only the DLL?
Steven_L_Intel1
Funcionário
5.711 Visualizações
You can provide the DLL, the export .LIB that gets created with it and the .MOD files. You don't need to provide source.
krishnabc
Principiante
5.711 Visualizações
DLL and .LIB are fine. I have worked withDLL before. But, .MOD is causing problems; hence, I am not that comfortable with it.Ok, I'll try.

Thank you.
Krishna
mecej4
Colaborador honorário III
5.711 Visualizações
MOD files need to be provided to the users of your code only if the code that they write to call your DLL will include USE statements for those modules. If the modules contain only interface declarations and no public variables, your users can be told to avoid USE statements, but they will have to write subroutine calls and function invocations with the correct calling sequence.

If any of the routines arguments are allocatable or optional, they will need to provide correct interfaces to the DLL routines. I don't see why you would object to giving them source code to only the interfaces to your routines that they are supposed to call.
krishnabc
Principiante
5.711 Visualizações
Thank you mecej4. Appreciate your advice. Will reportyou (or forum) later if I get any trouble.

Many thanks to you and Steve!
craig_h
Principiante
5.711 Visualizações
I'm having trouble with this as well. I have a project where I have a static library called by a console app (two separate projects in the same solution). I'm getting the same link error 2019. I've tried the following:

Added the static library debug directory to the Fortran general properties "Additional Include Directories" field of the console app project.
Added the static library debug directory to the Linker generalproperties "AdditionalLibrary Directories" field of the console app project.
Added the static library file name to the Linker input properties "Additional Dependencies" field of the console app project.

The static library was written by someone else and has only .FOR files and no module declarations. So I don't include any modules with a USE statement in my console app project.

Is how I should be including the static library in my console app? Does anyone have any ideas of why I'm getting a link error?

Thanks
Craig
Steven_L_Intel1
Funcionário
5.711 Visualizações
Craig,

What you've done should work, though there is an easier approach - making the library project a "dependent" of the executable. However, if you are still getting unresolved symbol references, there is more at issue. Please shoe the full text of at most three of these messages. Could it be that your project and the library project have different settings under "External procedures", such as one using CVF conventions and one not?
craig_h
Principiante
5.711 Visualizações
Steve
Actually I have declared the static library as a dependent of the .exe. This didn't seem to change anything other than the order they are compiled in and it alone didn't work so that's why I tried the approach mentioned above. Is there anything in the properties it shouldhave changed? I'm pretty new to these linking and compiler settings so I'm sure I just don't know what all to look at. I created both projects in IVF and they both have default settings under the"external procedures" properties. As I said I didn't write the static library source files so I don't know if there could be some preprocessor directives that would cause problems.

Below are two errors. The others are the similar just for different function calls.

Error 3 error LNK2019: unresolved external symbol __imp__SETMIX referenced in function _TRANSCOREFIG TRANSCOR2.obj

Error 4 error LNK2019: unresolved external symbol __imp__SATP referenced in function _TRANSCOREFIG TRANSCOR2.obj

Thanks for the help.
Craig
mecej4
Colaborador honorário III
5.711 Visualizações
Specifying "Additional Include Directories" only tells the compiler where to look for include and module files. Unless there is an INCLUDE or USE statement that cannot be satisfied by looking in the standard places, there is no need for the compiler to use the information provided, as is true in your case, since the source for that static library does not declare any modules.

If you can show the contents of the build log produced by a failed (because of linker errors) build, we could pin down the problem; without the necessary information, there are many different reasons for the link to fail, which we need not go into. In essence, was the library built before the linking attempt, and does the library contain all the external symbols needed?
Steven_L_Intel1
Funcionário
5.711 Visualizações
Providing more information helps. Your main program is trying to call routines it thinks are in a DLL - that have been declared (in the caller) with !DEC$ ATTRIBUTES DLLIMPORT. If what you have is actually a static library and not a DLL export library, that would explain the errors.
craig_h
Principiante
5.711 Visualizações

There are no !DEC$ ATTRIBUTES DLLIMPORT statements in my code. There are however !DEC$ ATTRIBUTES DLLEXPORT statements.

The following might be a clue from the build log. Why is it trying to create a .lib file? This is from my console app build log?

Link: executing 'link'

Creating library C:\Documents and Settings\chickman2\My Documents\Visual Studio 2005\Projects\MCCCv2.1\MCCCv2.1\debug\mcccv2.1.lib and object C:\Documents and Settings\chickman2\My Documents\Visual Studio 2005\Projects\MCCCv2.1\MCCCv2.1\debug\mcccv2.1.exp

MC3MAIN.obj : warning LNK4217: locally defined symbol _MC3CALC imported in function _COIL_FILE

TRANSCOR2.obj : error LNK2019: unresolved external symbol __imp__SETMIX referenced in function _TRANSCOREFIG

There are more errors that are similar to this error.

Do I need include statements for the .lib file in my console app? Does the .lib file need to be added to my console app project somewhere or should adding it in the properties as an additional dependency be enough?
Thanks
craig
Steven_L_Intel1
Funcionário
5.711 Visualizações
If you have a module with DLLEXPORT directives and then USE that module, they turn into DLLIMPORT directives. Your "static library" project is in fact a DLL project, which makes more sense. This will create an export library which should then be linked into the parent executable. This should happen if it is a dependent project.

The LNK4217 warning can be ignored.

Please attach the buildlog.htm from the executable project after a failed build.
craig_h
Principiante
5.711 Visualizações
Attached is my buildlog.

Thanks
Craig
Steven_L_Intel1
Funcionário
5.711 Visualizações
You have two different (I think) refpropv9.0.lib files listed in the link step. One of them appears to be one you added as a "source file" to the project. Not entirely sure where the other one comes from. Is this the library that is supposed to resolve these symbols? Can you attach the library to a reply here? It should be relatively small if it is DLL export library.
craig_h
Principiante
5.711 Visualizações
Unfortunately the library was purchased and I don't think I should post it here. I wouldn't want to get my company into any legal issues. It's about 27 source files. Not sure how many lines of code.

That might make since becasue I think at one point I had added the .lib file to the project not in the source files folder but just a general file.It has been removed from the poject so I'm not sure why it would still be trying to link to both.

I guess I'm trying to figure out the correct way of doing this. Would that have been an ok way of doing it? What's the technically correct way or does it matter? And is there a way I can get the linker to stop looking at both? Is there any other information that would help short of providing the entire library?

One other question. Is there documentation on theprepocessor directives such as !DEC$ ATTRIBUTES DLLIMPORT? I've seen several of them in examples but haven't found documentation for all the options.

Thanks
Craig
craig_h
Principiante
5.545 Visualizações
Steve
Here's the source of the two REFPROPv9.0.lib references in the buildlog. I tried compiling with different options and looked at the buildlog to figure this out.

1st instance
From adding the static library file name to the Linker input properties "Additional Dependencies" field of the console app project

2nd instance
From changing the Project Dependencies

I've tried compiling with different combinations of these with no luck. What are your thoughts?

Thanks
Craig
Responder