Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
30 Views

Is include necessary in compilation option?

Dear forum users,

I have a confusion about compilation option.

In MKL Link Line Advisor, If I select intel fortran, the compilation option always contains

 -I${MKLROOT}/include

and if I also select BLAS95 and LAPACK95, compilation option has one more term

 -I${MKLROOT}/include/intel64/lp64

I done a test in my makefile, and I found that if I don't add these include folder in my compilation option, but just adding '-mkl' or '-lmkl_intel_lp64 -lmkl_sequential -lmkl_core" in my linking option. The program also generated correctly. 

So I got serious confusion. It seems that "-I" is not necessary? Why link advisor always suggest "-I" in compilation option? What does "-I" really do in the compilation process? Why neglect "-I" still work?

best regards

0 Kudos
5 Replies
Highlighted
Black Belt
30 Views

The -I option to a compiler specifies additional directories to be searched. If these directories are already included by other means, such as by using an option such as -mkl, usually no harm is done. However, sometimes the order in which directories are searched may affect the compilation. In these cases, include files in different directories can define preprocessor macros differently, so having the directories searched in the intended order is important. On the other hand, if a needed directory is not specified, the compilation can fail (and usually does so).

Similar comments apply to the directories specified after the -L option. The issues with the -I option are minor when MKL is used from Fortran rather than from C, C++ and C#, since Fortran favors using modules for such purposes.

0 Kudos
Highlighted
Beginner
30 Views

mecej4 wrote:

The -I option to a compiler specifies additional directories to be searched. If these directories are already included by other means, such as by using an option such as -mkl, usually no harm is done. However, sometimes the order in which directories are searched may affect the compilation. In these cases, include files in different directories can define preprocessor macros differently, so having the directories searched in the intended order is important. On the other hand, if a needed directory is not specified, the compilation can fail (and usually does so).

Similar comments apply to the directories specified after the -L option. The issues with the -I option are minor when MKL is used from Fortran rather than from C, C++ and C#, since Fortran favors using modules for such purposes.

Hi, mecej4. Thank you so much.

I found I made a mistake. Specifying -mkl only in link option works for linux but not windows. I check out the document about '-mkl' option, it says

On Windows* OS, this option adds directives to the compiled code, which the linker then reads without further input from the driver. On Linux* OS and OS X, the driver must add the library names explicitly to the link command.

I don't quite understand what is the driver here?

I also tested two cases on windows

case 0:

ifort /c /mkl /I"%MKLROOT%"\include *90
ifort /mkl *obj

case 1:

ifort /c /I"%MKLROOT%"\include *90
ifort /mkl *obj

will have "unresolved external symbol"

case 2:

ifort /c /I"%MKLROOT%"\include *90
ifort mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib *obj

works.

So I don't understand. Does /I option write directory info into object files? And if so, why case 1 doesn't work? What is the difference between objects in case 0 and case 1?

0 Kudos
Highlighted
Black Belt
30 Views

Many options (such as /Qmkl vs. -mkl) are spelled differently in the Windows and Linux versions of the Intel Fortran compiler. The command that users commonly use (ifort.exe or ifort) is the driver program. It simply drives the compiler proper(fortcom.exe or fortcom) and linker (link.exe or ld), translating and modifying arguments as necessary.

Even if you are able to compile a source file to an object file without specifying /Qmkl, the linking will fail unless you explicitly list the MKL libraries in the link command line.

Using the Windows ifort compiler with the incorrect /mkl option generates an error message, which you should not ignore:

ifort: command line warning #10006: ignoring unknown option '/mkl'

You will probably benefit from consulting the MKL documentation when such questions occur.

0 Kudos
Highlighted
Beginner
30 Views

mecej4 wrote:

Many options (such as /Qmkl vs. -mkl) are spelled differently in the Windows and Linux versions of the Intel Fortran compiler. ...

Thank you so much, mecej4. 

Sorry for my typo, I acutally means /Qmkl. It is typo in my previous reply. 

I just tried case 4 on windows

ifort /c *90
ifort mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib *obj

it works.

But why "ifort /Qmkl *obj" doesn't work? So I still don't understand, what is "/Qmkl" exactly equivalent to ? I search the MKL documentation, there is no detailed information about what lib that  "/Qmkl" or "-mkl" link to. 

What is more, I still need a definite answer on whether "ifort /c /I"%MKLROOT%"\include" adds some directory info embedded into object files. I tried to compare object files bit by bit, but it seems that even the same makefile will generate different obj content each time.

0 Kudos
Highlighted
Black Belt
30 Views

If your Fortran code does not require interfaces to the MKL routines that it calls, and does not use any of the types that are defined in the MKL include files (such as MKL_INT), you do not need /Qmkl.

The compiler may include information on the date of creation, source file path, etc., into the OBJ file to aid the VS symbolic debugger. Similarly, it may insert includelib directives into the OBJ files to help the linker. See https://docs.microsoft.com/en-us/cpp/assembler/masm/includelib-masm. 

Please note that such internal details of how a compiler operates are often undocumented and may be changed without notice, so it may not be worthwhile to depend on these details.

0 Kudos