Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
27153 Discussions

[SOLVED] Linker error with "Hello World" in console, but successfully runs in VS2019 GUI

SergeyL
Beginner
663 Views

Hello!

I installed VS2019 Community and ifort 2021.1.2. 

If I create a new project inside VS2019 with default "Hello World" code, it perfectly runs using F5 command (Start Debugging). But if I try to compile and run the same code using command line with ifort helloworld.f90, I get LINK : fatal error LNK1104: cannot open file 'ifconsol.lib'.

I have tried to manually include path to fortran libs like

ifort helloworld.f90  /link /LIBPATH:"C:\Program Files (x86)\Intel\oneAPI\compiler\2021.1.2\windows\compiler\lib\intel64_win"

and in this case I get large list of errors. Here are start and end of this list:

LINK : error LNK2001: unresolved external symbol mainCRTStartup
libifcoremt.lib(for_reentrancy.obj) : error LNK2019: unresolved external symbol __imp_Sleep referenced in function for__reentrancy_cleanup
libifcoremt.lib(for_aio.obj) : error LNK2001: unresolved external symbol __imp_Sleep

OLDNAMES.lib(access.obj) : error LNK2001: unresolved external symbol __access
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\lib\x86\LIBCMT.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86\kernel32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86\uuid.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86\ImageHlp.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
helloworld.exe : fatal error LNK1120: 133 unresolved externals

Can't figure out how to fix it.
0 Kudos
2 Replies
Steve_Lionel
Black Belt Retired Employee
642 Views

You're using the 32-bit target compiler with 64-bit target libraries. The two don't mix.

When you start the command prompt, if you are using the Intel-installed shortcuts make sure you use the correct one. If you are doing it from a standard command prompt and invoking setvars.bat to establish the environment, make sure you select ia32 or intel64 as desired.

SergeyL
Beginner
625 Views

Thank you! Fixed by using setvars.bat (located in C:\Program Files (x86)\Intel\oneAPI). After executing "setvars.bat --force x64 vs2019", Visual Studio environment started to be initialized for x64 and now there is no problem with linking in console.

Reply