将MS C++与“英特尔Fortran”链接时出现致命错误LNK1104(找不到.lib文件)

fatal error LNK1104 (.lib file not found) when linking MS C++ with Intel Fortran

本文关键字:英特尔 LNK1104 致命错误 找不到 文件 lib C++ MS Fortran 链接      更新时间:2023-10-16

我有两个文件source1.f90main.cpp。Fortran文件有一个子例程,cpp文件有一个调用Fortran子例程的程序

我编译了Fortran文件,并使用以下命令行选项构建了一个静态库文件

ifort source1.f90 /nologo /debug:full /Od /gen-interfaces /warn:interfaces /traceback /check:bounds /libs:static /threads /dbglibs /c
lib /out:lib1.lib source1.obj

但是当我使用编译cpp文件时

CL main.cpp /link LIB1.LIB

我得到以下错误

D:temp>CL main.cpp /EHsc /link LIB1.LIB
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.60610.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
main.cpp
Microsoft (R) Incremental Linker Version 11.00.60610.1
Copyright (C) Microsoft Corporation.  All rights reserved.
/out:main.exe
LIB1.LIB
main.obj
LINK : fatal error LNK1104: cannot open file 'ifmodintr.lib'

如何解决此问题以便编译程序?

一般来说,您会错过Visual Studio中混合编程环境的设置。只需点击英特尔提供的链接:https://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications.

或者简单地说,在项目配置选项卡中添加fortran编译器包含目录和库目录。在我的情况下,fortran编译器目录是"g:\Program Files(x86(\IntelSWTools\compilers_and_libraries\windows\compiler\include\intel64",而库目录是"g:\Program Files。