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

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

SergeyL
Beginner
2,478 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
1 Solution
Steve_Lionel
Honored Contributor III
2,457 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.

View solution in original post

3 Replies
Steve_Lionel
Honored Contributor III
2,458 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
2,440 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.

0 Kudos
Anders_S_1
New Contributor III
1,572 Views

Hi Steve,

Thanks for a swift answer!

Yes, I had used the 32-bit command line.

Maybe these lines should start with 32 or 64, in order to reduce risks for error!

Best regards

Anders S

0 Kudos
Reply