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

Undefined externals on XP64 with Ifort 9.1

connell
Beginner
1,236 Views

I have installed VS 2005, Intel 9.1 (C and FORTRAN) and am trying to compile a simple program from a cygwn window. I am getting undefined externals - am I missing a library?

GECRD-E65569F5C> ifort maxmem.f
Intel Fortran Compiler for Intel EM64T-based applications, Version 9.1
Build 20060324
Copyright (C) 1985-2006 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

-out:maxmem.exe
-subsystem:console
maxmem.obj
LIBCMT.lib(open.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
LIBCMT.lib(initcon.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
libifcoremt.lib(for_nt_open_proc.obj) : error LNK2019: unresolved external symbol __imp_CloseHandle referenced in function for__reopen_file
libifcoremt.lib(for_close_proc.obj) : error LNK2001: unresolved external symbol__imp_CloseHandle
LIBCMT.lib(thread.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
LIBCMT.lib(close.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
libifcoremt.lib(for_reentrancy.obj) : error LNK2001: unresolved external symbol__imp_CloseHandle
libifcoremt.lib(for_lub_mgt.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
libifcoremt.lib(for_diags_intel.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
libifcoremt.lib(for_avalloc.obj) : error LNK2001: unresolved external symbol __imp_CloseHandle
libifcoremt.lib(for_reentrancy.obj) : error LNK2019: unresolved external symbol__imp_Sleep referenced in function for__acquire_semaphore_threaded
libifcoremt.lib(for_get.obj) : error LNK2001: unresolved external symbol __imp_Sleep
LIBCMT.lib(crtheap.obj) : error LNK2001: unresolved external symbol __imp_Sleep
ifconsol.lib(for_m_console.obj) : error LNK2001: unresolved external symbol __im

0 Kudos
9 Replies
Steven_L_Intel1
Employee
1,236 Views
Strange. Those should be pulled in from kernel32.lib automatically. What happens if you don't use Cygwin? Are youi perhaps getting a "wrong" kernel32.lib? What's the definition of LIB in your shell?
0 Kudos
connell
Beginner
1,236 Views

The LIB variable is defined as:

GECRD-E65569F5C> printenv LIB
C:Program Files (x86)Microsoft Visual Studio 8VCPlatformSDKLIB;
C:Program FilesMicrosoft Visual Studio 8VCLIB;
c:Program Files (x86)IntelCompilerFortran9.1EM64TLIB;
c:Program Files (x86)IntelCompilerC++9.1EM64TLIB;

I had to add some mods to the LIB, PATH and INCLUDE variables in the .bashrc file to get things to work. These changes were intended to mirror the ifortvars and clvars.bat files plus changes so that cl.exe etc can be found. The mods are shown below.

#############################
#############################
##"c:/Program Files (x86)/Intel/Compiler/C++/9.1/em64t/bin/iclvars.bat"
export ICPP_COMPILER91="/cygdrive/c/Program Files (x86)/Intel/Compiler/C++/9.1"
export PATH="${ICPP_COMPILER91}/EM64T/BIN":${PATH}

export ICPP_COMPILER91="c:Program Files (x86)IntelCompilerC++9.1"
export LIB="${ICPP_COMPILER91}EM64TLIB;${LIB}"
export INCLUDE="${ICPP_COMPILER91}EM64TINCLUDE;${INCLUDE}"
#
###############################
##"c:/Program Files (x86)/Intel/Compiler/Fortran/9.1/em64t/bin/ifortvars.bat"

export IFORT_COMPILER91="/cygdrive/c/Program Files (x86)/Intel/Compiler/Fortran/9.1"
export PATH="${IFORT_COMPILER91}/EM64T/BIN":${PATH}

export IFORT_COMPILER91="c:Program Files (x86)IntelCompilerFortran9.1"
export LIB="${IFORT_COMPILER91}EM64TLIB;${LIB}"
export INCLUDE="${IFORT_COMPILER91}EM64TINCLUDE;${INCLUDE}"

##################################
##################################
#
# Visual Studio 2005 (cl and associated dll's)
export PATH="/cygdrive/C/Program Files/Microsoft Visual Studio 8/VC/BIN":$PATH
export PATH="/cygdrive/C/Program Files/Microsoft Visual Studio 8/Common7/IDE":$PATH
export LIB="C:Program FilesMicrosoft Visual Studio 8VCLIB;${LIB}"
export LIB="C:Program Files (x86)Microsoft Visual Studio 8VCPlatformSDKLIB;${LIB}"

0 Kudos
TimP
Honored Contributor III
1,236 Views
The normal way (IMHO) to use a cygwin shell with ifort is to open the appropriate ifort build environment window, then run the cygwin.bat in that window. That way, the cygwin shells inherit all the ifort environment variables, if the ifortvars.bat is correct. ifort.cfg also must be fixed, when the installer doesn't do it, but that is not the problem here.
0 Kudos
connell
Beginner
1,236 Views
I tried doing something like that but I had problems finding "cl" and some libs/dlls without explicitly modifying the PATH variable. Having done this I decided to add the ifortvars and clvars to the .bashrc as well.
0 Kudos
Steven_L_Intel1
Employee
1,236 Views
It looks to me as if you're pulling in the X86 version of the Win32 API libraries with that definition of LIB. You want it to get the "X64" libraries instead. If you had run ifortvars.bat it would do this properly.
0 Kudos
connell
Beginner
1,236 Views

Steve - thanks for the info. It turned out it was the definition of the LIB variable.

I would like to use ifortvars.bat and iclvars.bat files to set up paths etc. However I need to build the code in a cygwin window hence the need to convert to a ksh type format as I don't know of any way to make the ksh inherit stuff from a com script. I also found the bat files don't set the paths and env vars for the CL compiler. Maybe I am missing something here

0 Kudos
Steven_L_Intel1
Employee
1,236 Views
ifortvars.bat invokes the setup script for either Visual Studio or the Platform SDK, depending on which is appropriate. This is what establishes paths for cl.
0 Kudos
TimP
Honored Contributor III
1,236 Views

A correctly set up ifort.cfg also is required in order for ifort to find Microsoft components required at link time, or when attempting to run CL from the Fortran command window. When that isn't correct, cygwin may substitute its own (32-bit) link, and so the errors are confusing. In my own opinion, ifort should furnish a sample ifort.cfg and mention in the documentation the guidelines for setting it up, if the installer cannot be corrected to make ifort install automatically with Microsoft PSDK. I suppose this is a symptom of the moving target presented by Microsoft software. I have submitted several QuAD issues on this. The compiler team was able to correct known problems with ifortvars.bat setup, but not ifort.cfg.
Last week, on my x64 installation, CL was not invoking libraries properly in its own PSDK command window, so it should not be surprising that it continues to have difficulty in the ifortvars.bat window. This is separate from the problems occasioned by ifort setup not filling in ifort.cfg so that ifort can link; I have edited both icl.cfg and ifort.cfg so those compilers are working. I don't think many people care whether CL can run on its own in the ifort command window, if it can build objects which work in an ifort build.
0 Kudos
Steven_L_Intel1
Employee
1,236 Views
ifort does provide a default ifort.cfg and it explicitly specifies the linker to use. The installer works fine with the PSDK. The issue here seems to be the inability of the Cygwin environment to properlu inherit the definitions that ifort.bat sets up.

ifort.cfg has nothing to do with this particular problem.
0 Kudos
Reply