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

ifort linker can't find my user libs

Lowell_S_
Beginner
1,691 Views

I've searched the forum for this issue but no luck.  

This is my first time trying to link user libs into my source code on linux.
I am NOT using -static or -fast when I compile.  

libA.a and libB.a are both archive files I created.

My link statement is,
-L. -l:libA.a -l:libB.a

When I try to compile my program I get the following.

ifort  -L. -llibA.a -llibB.a -o prog.exe
ld: cannot find -llibA.a

Yes, the lib files are located in the same directory as the makefile and source code.

Any suggestions?  Thanks!

0 Kudos
1 Solution
Lorri_M_Intel
Employee
1,691 Views

On Linux, the ld utility takes the argument to the  "-l" switch and prepends the letters "lib" and postfixes either .a or .so until it finds a match.

So, assuming your libraries are literally named "libA.a" and "libB.a", please try this command:

ifort  -L. -lA -lB -o prog.exe

 

                --Lorri

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,691 Views

Linux-speak is a bit different. You want:

-L. -lA -lB

 

0 Kudos
TimP
Honored Contributor III
1,691 Views

The syntax is of the form

ifort *.f  -lA -lB

If you mean to compile and link all the .f files in the current directory.  It won't work without source and/or object files prior to the -l directives.  As Lorri reminded us, -l implies lib and .a or .so.  I don't know what Makefile fortmat you are using; what you show doesn't look standard.

The form required by the standard linux utility ld, has overwhelming documentation. 

https://www.gnu.org/software/binutils/

-L./ is OK if the .a files are in the current working directory, but probably redundant.
 

0 Kudos
Lorri_M_Intel
Employee
1,692 Views

On Linux, the ld utility takes the argument to the  "-l" switch and prepends the letters "lib" and postfixes either .a or .so until it finds a match.

So, assuming your libraries are literally named "libA.a" and "libB.a", please try this command:

ifort  -L. -lA -lB -o prog.exe

 

                --Lorri

0 Kudos
Lowell_S_
Beginner
1,691 Views

Thanks for the help. I'm not very knowledgeable on compiling and linking with various systems so sometimes trying to interpret overwhelming documentation can be difficult.

Once I understood the prepend lib and postpend .a characteristics, I got it to work. Lorri's response was the easiest for me to understand.  Thanks, all.

0 Kudos
Reply