Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28595 Discussions

Rebuilding .mod file and compiling in Xcode

seniorrojo
Beginner
803 Views
Hello,

I was wondering if someone could answer a question about a .mod file situation that I do not
understand.

I have created a module file in my project: module variablesmc, in my project. When I first compile
the program, I receive an error message (which I think is correct because the compilier is building
the variablesmc.mod file). When I compile the program a second time, the error messages
go away and the file is built.

One of the parameters that I set is written to the screen and I can view it after running the
program. The problem ariseswhen I want to change this parameter. If I delete the variables.mc file
from the:project_name/build/project.build/debug folder (to let the compilier rebuild the file with the
new parameter value) and I run the program again, the .mod file is rebuilt, but the parameter value
remains the same. The same thing happens if I completely delete the build folder.

So, the question is, what do I need to delete to get the compilier to rebuild this file so that this parameter
will be changed for my program run with this new parameter.

In addition, I am using Xcode as my developing UI. For some reason, it appears that when I change
this .mod file, I have to recompile each file that uses these parameters individually. I thought that if
I just used the "Build and Go" procedure, this would recompile all of the files in the project. Is there
some setting that I have to change to recompile all of the files in my project?

Thanks,

Chris.

0 Kudos
4 Replies
Ron_Green
Moderator
803 Views
Chris,

This is a known limitation of the Intel Fortran Compiler Pro for Mac OS X and it's integration into Xcode - module dependencies are not recognized or properly handled by the Build process within Xcode. This is one of the reasons this integration is called a "Preview Feature". It is unfortunate, since modules are key to any modern Fortran program. The best I can recommend is to follow the advice in the document to manually order the build order s.t. the module(s) and dependent procedures are built in the correct order. Here is the snippet from the documentation:

You can change the compilation order of the files in an Xcode target. This is especially useful for compiling Fortran sources that define modules (producing .MOD files). These can, in turn, be used by Fortran sources that use the modules. To re-order the files listed under a target's Compile Sources build step, click a source and drag it before or after other compilations.
0 Kudos
seniorrojo
Beginner
803 Views
Chris,

This is a known limitation of the Intel Fortran Compiler Pro for Mac OS X and it's integration into Xcode - module dependencies are not recognized or properly handled by the Build process within Xcode. This is one of the reasons this integration is called a "Preview Feature". It is unfortunate, since modules are key to any modern Fortran program. The best I can recommend is to follow the advice in the document to manually order the build order s.t. the module(s) and dependent procedures are built in the correct order. Here is the snippet from the documentation:

You can change the compilation order of the files in an Xcode target. This is especially useful for compiling Fortran sources that define modules (producing .MOD files). These can, in turn, be used by Fortran sources that use the modules. To re-order the files listed under a target's Compile Sources build step, click a source and drag it before or after other compilations.

Hi Ronald,

Thank you for your reply.

If I am understanding you correct, when I change a parameter in my mod file I
need to delete the project_name/build/project.build folder first and then
recompile the project. In addition, I need to change the order of the files in
the project so that the files that use the parameters that I have changed get
recompiled (rebuilt) first. Is that correct? Or, do I need to build each
individual file again?

Do you know if there is a setting in Xcode that lets you see the date/time
of when the file has been recompiled (from the UI) so I know what needs
to be rebuilt and what hasn't?

When I do perform a "build and go" the subroutines within the project
do get re-compiled, right? I guess I am a little confused about why the
order of the files is important.

As a new user of Xcode, I am not that attached to it. Would you recommend
a better UI tool that I could use with the Intel compiler on the Mac
that has better features or will this issue get fixed in the future?

Thanks again for your time and assistance,

Chris.



0 Kudos
Kevin_D_Intel
Employee
803 Views

The initial error experienced about the missing module file relates to not having the required dependency information. It occurs when the Xcode Fortran project (with modules) is built the first time (or after a clean) regardless if one follows rules about ordering source files under the target as discussed below. The work-around is to simply rebuild the target a second time.

When you change the parameter in your module source file, you must Clean the target, and then as an extra precaution manually remove the .mod files that arecreated within the specific configuration subdirectory (e.g. Debug or Release), and then rebuild the target. There is no need to remove directories you mentioned. Removing the .mod files is also not required because the .mod file will be regenerated for the source file you modified. In addition to not maintaining dependency information, another flaw in the current Fortran Xcode integrations is that the Clean operation does not remove .mod files.

The UI only recompiles source files that have been modified, therefore, if you only modify the source file containing the module with the parameter, then none of the other source files that USE the module (and the parameter) will be recompiled, therefore, the link will re-use the existing object files (.o files) which have the old parameter value compiled in. That is why you saw the program still using the old parameter value.

As to ordering the source files under Xcode, as you know you must add each specific source file under the Compile Sources group for your target. The order that source files appear under this group implies their compilation order. Therefore, if the application uses modules, you must list the corresponding source files in an order that ensures the module source files are compiled first.

For example, assume the program has three source files: myvars.f90, sub.f90, main.f90. Where myvars.f90 contains a module definition used only used sub.f90. When you create the target under Xcode, when adding these source files to the target you must either add them or re-arrange them after adding them, so that myvars.f90 is listed before sub.f90. This ensures myvars.f90 is compiled before sub.f90 which is necessary to ensure the corresponding myvars.mod exists when compiling sub.f90.

As you experienced, following this source file ordering rule does not avoid that one-time compilation error discussed earlier. So you should expect to rebuild the target at least twice after a complete clean and removing the .mod files. If you are only modifying source files that contain no modules, a full clean is not necessary and a rebuild will only recompile those source files that were modified and relink the executable with the corresponding new object files.

Xcode is the only available UI tool on the Mac that we integrate with. We hope these existing limitations can be addressed in the future in cooperation with Apple although currently there is no timeframe available for when.

I hope this helps.
0 Kudos
seniorrojo
Beginner
803 Views

The initial error experienced about the missing module file relates to not having the required dependency information. It occurs when the Xcode Fortran project (with modules) is built the first time (or after a clean) regardless if one follows rules about ordering source files under the target as discussed below. The work-around is to simply rebuild the target a second time.

When you change the parameter in your module source file, you must Clean the target, and then as an extra precaution manually remove the .mod files that arecreated within the specific configuration subdirectory (e.g. Debug or Release), and then rebuild the target. There is no need to remove directories you mentioned. Removing the .mod files is also not required because the .mod file will be regenerated for the source file you modified. In addition to not maintaining dependency information, another flaw in the current Fortran Xcode integrations is that the Clean operation does not remove .mod files.

The UI only recompiles source files that have been modified, therefore, if you only modify the source file containing the module with the parameter, then none of the other source files that USE the module (and the parameter) will be recompiled, therefore, the link will re-use the existing object files (.o files) which have the old parameter value compiled in. That is why you saw the program still using the old parameter value.

As to ordering the source files under Xcode, as you know you must add each specific source file under the Compile Sources group for your target. The order that source files appear under this group implies their compilation order. Therefore, if the application uses modules, you must list the corresponding source files in an order that ensures the module source files are compiled first.

For example, assume the program has three source files: myvars.f90, sub.f90, main.f90. Where myvars.f90 contains a module definition used only used sub.f90. When you create the target under Xcode, when adding these source files to the target you must either add them or re-arrange them after adding them, so that myvars.f90 is listed before sub.f90. This ensures myvars.f90 is compiled before sub.f90 which is necessary to ensure the corresponding myvars.mod exists when compiling sub.f90.

As you experienced, following this source file ordering rule does not avoid that one-time compilation error discussed earlier. So you should expect to rebuild the target at least twice after a complete clean and removing the .mod files. If you are only modifying source files that contain no modules, a full clean is not necessary and a rebuild will only recompile those source files that were modified and relink the executable with the corresponding new object files.

Xcode is the only available UI tool on the Mac that we integrate with. We hope these existing limitations can be addressed in the future in cooperation with Apple although currently there is no timeframe available for when.

I hope this helps.

Hello Kevin,

Thank you for your reply and for answering my question! This helps a lot!

Chris.


0 Kudos
Reply