Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Link error using makefile

John_S_
Beginner
129 Views

This is a simple test for ifort.

test.90:

integer a,b,c
a = 1
b = 2
call sub(a,b,c)
write(*,*)'c=',c
stop
end

sub.f90:

subroutine sub(a,b,c)
integer a,b,c
c=a+b
return
end

The makefile is:

lib     = sub.lib
exe     = test.exe


$(lib):
    ifort /c sub.f90
        lib /out:$(lib) sub.obj

$(exe):
        ifort test.f90 sub.lib

clean:
 -del *.exe *.obj

I first make the library with the command

make sub.lib

Then I try to make the exe with the command

make test.exe

This gives an error on linking - LNK1104: Cannot open file ifconsol.lib.

However, if I give the command

ifort test.f90 sub.lib

at the command prompt, the program is made without error.

Why is the makefile causing this error?

Thank you.

 


 

 

0 Kudos
3 Replies
Kevin_D_Intel
Employee
129 Views

Change all uses of "lib" in your makefile to some other spelling (e.g. mylib). As is, the name interferes with the LIB environment variable and throws off the linker. Another way to see the interference is to run nmake with the /E option; however, /E is not the solution though, renaming 'lib' is.

IanH
Black Belt
129 Views

Your makefile obliterates the LIB environment variable that the linker uses for the library search path.

Rename the `lib` variable in your makefile to something else.
 

John_S_
Beginner
129 Views

ianh wrote:

Your makefile obliterates the LIB environment variable that the linker uses for the library search path.

Rename the `lib` variable in your makefile to something else.
 

Thank you Kevin and Ian. It is now working.

 

Reply