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

Link error using makefile

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
Highlighted
Employee

Change all uses of "lib" in

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.

0 Kudos
Highlighted
Black Belt

Your makefile obliterates the

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.
 

0 Kudos
Highlighted
Beginner

Quote:ianh wrote:

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.

 

0 Kudos