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

Newbie question: ifort library path

hmalissa
Beginner
2,451 Views

Is there a way to adjust the library path settings that ifort uses?

The question might be trivial, but I haven't found an answer up to now. I wrote a few subroutines and put them into a static library using ar:

$ifort -c xxx.f && ifort -c yyy.f && ifort -c zzz.f

$ar rcs libxyz.a xxx.o yyy.o zzz.o

That works fine so far. I can use the library:

$ifort -o testxyz testxyz.f -L. -lxyz

And it compiles and runs fine. I want to put libxyz.a in certain directory, say ~/lib/, and I want ifort to automatically look for libraries in that directory, so I do not need to specify the "-L." option in the future. How can I configure ifort to look for libraries also in ~/lib/ ? I do not have root-access on this machine, so I don't want to influence the system-wide behavior of ifort.

0 Kudos
4 Replies
Cijo_Abraham_Mani
2,451 Views
Quoting - hmalissa

Is there a way to adjust the library path settings that ifort uses?

The question might be trivial, but I haven't found an answer up to now. I wrote a few subroutines and put them into a static library using ar:

$ifort -c xxx.f && ifort -c yyy.f && ifort -c zzz.f

$ar rcs libxyz.a xxx.o yyy.o zzz.o

That works fine so far. I can use the library:

$ifort -o testxyz testxyz.f -L. -lxyz

And it compiles and runs fine. I want to put libxyz.a in certain directory, say ~/lib/, and I want ifort to automatically look for libraries in that directory, so I do not need to specify the "-L." option in the future. How can I configure ifort to look for libraries also in ~/lib/ ? I do not have root-access on this machine, so I don't want to influence the system-wide behavior of ifort.

0 Kudos
Cijo_Abraham_Mani
2,451 Views
Quoting - cijoaj2003
Quoting - hmalissa

Is there a way to adjust the library path settings that ifort uses?

The question might be trivial, but I haven't found an answer up to now. I wrote a few subroutines and put them into a static library using ar:

$ifort -c xxx.f && ifort -c yyy.f && ifort -c zzz.f

$ar rcs libxyz.a xxx.o yyy.o zzz.o

That works fine so far. I can use the library:

$ifort -o testxyz testxyz.f -L. -lxyz

And it compiles and runs fine. I want to put libxyz.a in certain directory, say ~/lib/, and I want ifort to automatically look for libraries in that directory, so I do not need to specify the "-L." option in the future. How can I configure ifort to look for libraries also in ~/lib/ ? I do not have root-access on this machine, so I don't want to influence the system-wide behavior of ifort.

I am suggesting you to add a link to both the directory and the library file in shared objects folder so that the problem might just get fixed and you need not have to use a "-L" option in the future .

I was trying really hard to delete my previous , but I cannot . Is there a bug as the post was made automatically as I tried to reply to the thread .

My answer is now added " I am suggesting you to add a link to both the directory and the library file in shared objects folder so that the problem might just get fixed and you need not have to use a "-L" option in the future ."

0 Kudos
Kevin_D_Intel
Employee
2,450 Views
Welcome to the Intel Fortran User Forum!

The ifort.cfg is one mechanism available to accomplish what you want, however, that affects all users.

A method providing user-only private control is to create a shell alias. For bash, you can create an ifort alias using:

alias ifort='ifort -L/myhomepath/lib'

As discussed below, both methods also only work for hiding the L option.

You will not gain much by hiding L option inside ifort.cfg or the alias. The linker (ld), which is invoked by ifort, does not simply search every static library residing a directory specified via L. Using user-supplied libraries requires one specify the L (unless the library resides in ".") and then a separate l option for each specific user library to search.

I do not follow the earlier suggestion regarding sym-links, but if you really want to hide the L, the easiest option to suit your needs is to ues the alias. To use a custom ifort.cfg, you would simply edit it accordingly. Using your earlier example, you would do the following:

Edit ifort.cfg so it contains the L path of interest. You cannot use the ~ to refer to your home directory. You must spell it out completely, so replace myhomepath below with the fully qualified path.

ifort.cfg would contain:

-L/myhomepath/lib

Then you can invoke ifort as follows when using either the alias or the custom ifort.cfg:

ifort -o testxyz testxyz.f -lxyz

From testing I conducted, you will only be able to place the L option into ifort.cfg or the alias. The link fails when placing both the L and l options in ifort.cfg or the alias because the l option gets positioned on the ld command line ahead of the actual object corresponding to the testxyz.f source file.

Good luck!

0 Kudos
Hirchert__Kurt_W
New Contributor II
2,450 Views
Welcome to the Intel Fortran User Forum!

The ifort.cfg is one mechanism available to accomplish what you want, however, that affects all users.

A method providing user-only private control is to create a shell alias. For bash, you can create an ifort alias using:

alias ifort='ifort -L/myhomepath/lib'

As discussed below, both methods also only work for hiding the L option.

You will not gain much by hiding L option inside ifort.cfg or the alias. The linker (ld), which is invoked by ifort, does not simply search every static library residing a directory specified via L. Using user-supplied libraries requires one specify the L (unless the library resides in ".") and then a separate l option for each specific user library to search.

I do not follow the earlier suggestion regarding sym-links, but if you really want to hide the L, the easiest option to suit your needs is to ues the alias. To use a custom ifort.cfg, you would simply edit it accordingly. Using your earlier example, you would do the following:

Edit ifort.cfg so it contains the L path of interest. You cannot use the ~ to refer to your home directory. You must spell it out completely, so replace myhomepath below with the fully qualified path.

ifort.cfg would contain:

-L/myhomepath/lib

Then you can invoke ifort as follows when using either the alias or the custom ifort.cfg:

ifort -o testxyz testxyz.f -lxyz

From testing I conducted, you will only be able to place the L option into ifort.cfg or the alias. The link fails when placing both the L and l options in ifort.cfg or the alias because the l option gets positioned on the ld command line ahead of the actual object corresponding to the testxyz.f source file.

Good luck!

If your shell is tcsh (or some other version of the C shell), you could use command history to control the placement of arguments relative to fixed text in your alias:

alias ifort 'ifort -L/myhomepath/lib !* -lxyz'

The bash version of alias is more restriced and can't do this, but bash has shell functions that can:

function ifort () { command ifort -L/myhomepath/lib "$@" -lxyz }

-Kurt

Disclaimer: At the time I am posting this, I do not have convenient access to a Linux system, so I am posting the above alias and function without testing them. I have written similar aliases and functions in the past, so I have every reason to believe that the above will work, but there is always the possibility that there is some detail that I've incorrectly specified.

0 Kudos
Reply