链接:致命错误 LNK 1104:无法打开文件“LIBCMT.lib”

发布于 2025-01-07 00:00:54 字数 1190 浏览 2 评论 0原文

请帮忙,我花了一整天的时间试图编译我的 C++ 应用程序。

我的项目包含一个源文件:Foo.cpp。这是它的代码:

#include <jni.h>
#include <com_Foo.h>

JNIEXPORT jint JNICALL Java_com_Foo_add
(JNIEnv * env, jobject obj, jint x, jint y)
{
    return x+y;
}

如您所见,我正在尝试使用 JNI,但我认为这与问题没有任何关系。这是我在命令行上尝试的:

C:\Users\michael\cworkspace\foo>cl -LD Foo.cpp -FeFoo.dll
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Foo.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/dll
/implib:Foo.lib
/out:Foo.dll
Foo.obj
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'

在我的环境中我设置了:

包括: C:_\include;C:\frankenstein\includes;C:\Program Files\Java\jdk1.6.0_24\include;C:\Program Files\Java\jdk1.6.0_24\include\win32;C:_\include \win32;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include

LIBPATH: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib

我检查了lib目录,它包含一个“libcmt.lib”文件。不知道是否区分大小写,但我知道我从未更改过 Visual Studio 文件或目录中的任何内容。

有人可以告诉我如何才能完成这项工作吗?

Please help, I have spent all day trying to make my c++ app compile.

My project contains one source file: Foo.cpp. Here is its code:

#include <jni.h>
#include <com_Foo.h>

JNIEXPORT jint JNICALL Java_com_Foo_add
(JNIEnv * env, jobject obj, jint x, jint y)
{
    return x+y;
}

as you can see I was trying to use JNI, but I don't think that has anything to do with the problem. Here is what I tried on the command line:

C:\Users\michael\cworkspace\foo>cl -LD Foo.cpp -FeFoo.dll
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Foo.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/dll
/implib:Foo.lib
/out:Foo.dll
Foo.obj
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'

In my environment I have set:

INCLUDE:
C:_\include;C:\frankenstein\includes;C:\Program Files\Java\jdk1.6.0_24\include;C:\Program Files\Java\jdk1.6.0_24\include\win32;C:_\include\win32;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include

LIBPATH:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib

I checked in the lib directory, it contains a "libcmt.lib" file. Don't know if it is case sensitive, but I know that I never changed anything in the visual studio files or directories.

Would somebody please tell me how I can make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

妞丶爷亲个 2025-01-14 00:00:54

在 2018 年底恢复这个线程,因为其他解决方案都没有帮助我的情况:)

对我来说,在我为一个完全不相关的项目安装Windows 驱动程序套件后,这个错误开始突然出现。 >。

如果您不需要“Spectre Mitigation”(您很可能不需要)并且看到此错误,则很可能您只需设置项目属性(属性页)-> 即可。配置属性-> C/C++->代码生成->幽灵缓解禁用

神奇的是,所有项目中 WDK 的 Visual Studio 工具安装程序都将其设置为启用,即使它们与 WDK 无关,也没有为任何驱动程序相关内容选择平台工具集。微软处于最佳状态。

Resurrecting this thread in late 2018 since none of the other solutions helped my case :)

For me this error started appearing out of nowhere after i installed Windows Driver Kit for a completely unrelated project.

If you don't need "Spectre Mitigation" (you most likely do not) and seeing this error it's highly probable that you just have to set Project Properties (property pages) -> Configuration Properties -> C/C++ -> Code Generation -> Spectre Mitigation to Disabled.

Magically it was set to Enabled by the installer of Visual Studio tools for WDK in all projects even tho they got nothing to do with WDK nor the Platform toolset was selected for any driver related stuff. Microsoft at its finest.

心意如水 2025-01-14 00:00:54

我怀疑您用来运行编译器的命令提示符没有定义所有必需的环境变量。

为了确保命令行环境配置正确,请确保您已运行 vsvars32.bat 批处理文件。

I suspect the command prompt you are using to run the compiler does not have all the required environment variables defined.

To make sure the command line environment is correctly configured make sure you have run the vsvars32.bat batch file.

落墨 2025-01-14 00:00:54

只是在这里添加我的经验,因为它可能对某人有帮助,并且它适用于较新的 VS 版本(我的例子是 2017 年)。

当我将项目移动到新机器时,我在编译过程中遇到了类似的错误。我终于发现我的依赖项中的一个项目打开了幽灵缓解功能,并且默认情况下不包含具有该支持的库:

在此处输入图像描述

Just to add my experience here, since it may help someone, and it applies to newer VS editions (2017 in my case).

I was getting a similar error during compiling when I moved my project to a new machine. I finally figured out that one of the projects in my dependencies had spectre mitigation turned on, and the libs with that support are not included by default:

enter image description here

罪歌 2025-01-14 00:00:54

当我得到……本例中您的项目名称==“项目名称”时,这对我有用

fatal error LNK1104: cannot open file 'LIBCMT.lib'

转到您的项目的“解决方案资源管理器”窗口。

右键单击项目“项目名称”,而不是解决方案“项目名称”。

这将打开一个长菜单。

底部是“属性”,单击它。

这将打开“项目名称”属性页窗口。

如果窗口的名称(左上角)显示...

“解决方案‘项目名称’属性页

关闭此窗口,您右键单击的是解决方案,而不是项目,您需要右键单击项目名称。

在“项目名称”属性页

左侧面板上展开配置属性

然后单击常规

现在右侧面板应显示“当前项目的常规“配置属性”。

请向下查找列表中的“平台工具集

如果您使用的 VS 版本不是列出的您需要更改的版本,

。要更改 VS 的版本,只需将鼠标指针放在显示的当前 VS 版本名称的末尾并单击即可。

该行的右侧将显示一个带有向下箭头的框,单击它。

这将打开一个包含 VS 版本列表的窗口。

选择您现在使用的 VS 版本。

该窗口应该关闭,并且您的选择应该替换了我第一次构建时用于构建项目的旧项目 VS 版本。

然后在“项目名称”属性页底部单击应用,然后单击确定

现在尝试构建项目。

我希望这会有所帮助,当我处理使用早期版本的 VS 构建的项目时,它对我有用。

祝你好运,迈克。

This worked for me when I got …

fatal error LNK1104: cannot open file 'LIBCMT.lib'

Your project name == “Project Name” for this example.

Go to the 'Solution Explorer' window for your Project.

RIGHT Click on the Project "Project Name", not the Solution "Project Name".

This will open a long menu.

At the bottom is "Properties" Click on it.

This will open the “Project Name” Property Pages window.

IF the name of the window (upper left) says...

“Solution 'Project Name' Property Pages

Close this window, you right clicked on the Solution, not the Project, you need to right click on the project name.

On the “Project Name” Property Pages

Left hand panel expand Configuration Properties

Then click on General

Now the right panel should show the 'General' Configuration Properties' for your current Project.

Look down the list to 'Platform Toolset'

If the version of VS you are using is not the one listed you needed to change it.

To change the version of VS just put you mouse pointer at the end of the current VS version name that is displayed and click.

A box with a down arrow will show at the right hand side of that row, click on it.

This will open a window with a list of VS versions.

Pick the version of VS you are NOW using.

That window should close, and your selection should have replaced the old project VS version that was used to build your project when I was first built.

Then at bottom of “Project Name” Property Pages click Apply, then OK.

Now try to build Project.

I hope this helps, it works for me when working on projects that were built with earlier versions of VS.

Good luck Mike.

A君 2025-01-14 00:00:54

直接运行 cl.exe 需要设置指向库和工具的环境变量。要了解需要安装哪些变量以及它们的值应该是什么,我建议安装 适用于 Python 2.7 的 Microsoft Visual C++ 编译器。它将命令提示符添加到开始菜单,自动加载所需的环境变量。

运行提示后,运行 set 以查看所有环境变量。

示例:

LIB=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Lib;C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib;
LIBPATH=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Lib;C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib;
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
VCINSTALLDIR=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\
WindowsSdkDir=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\

Running cl.exe directly requires that environment variables are set that point to libraries and tools. To get an idea of what variables need installed and what their values should be, I recommend installing Microsoft Visual C++ Compiler for Python 2.7. It adds command prompts to the start menu which automatically load the needed environment variables.

After running the prompt, run set to see all of the environment variables.

Examples:

LIB=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Lib;C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib;
LIBPATH=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Lib;C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib;
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
VCINSTALLDIR=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\
WindowsSdkDir=C:\Users\JBeach\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\
酒解孤独 2025-01-14 00:00:54

在尝试在 Win10 上安装 rasPi Pico SDK 时,似乎遇到了同样的错误(当然没有找到 libcmt.lib),解决方案是运行 vcvars64.bat(在我的安装中)位于:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build 在命令行上,然后重新运行 nmake。

Having just hit seemingly this same error (certainly the libcmt.lib not found) whilst trying to install the rasPi Pico SDK on Win10, solution was to run vcvars64.bat which (on my install) was located in :
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build on the command line and then rerun nmake.

鹤仙姿 2025-01-14 00:00:54

右键单击项目名称(在解决方案资源管理器中)-> 属性 -> 链接器 -> 一般 -> 其他库目录并设置如下:

$(SolutionDir)$(Platform)\$(Configuration)\;$(VCToolsInstallDir)\lib\$(PlatformShortName);$(VCToolsInstallDir)atlmfc\lib\$(PlatformShortName)

Right click on ProjectName (within Solution Explorer) -> Properties -> Linker -> General -> Additional Library Directories and set it like this:

$(SolutionDir)$(Platform)\$(Configuration)\;$(VCToolsInstallDir)\lib\$(PlatformShortName);$(VCToolsInstallDir)atlmfc\lib\$(PlatformShortName)
假面具 2025-01-14 00:00:54

VS2012 开发人员命令提示符命令窗口运行 cl.exe 时,我遇到了同样的错误。结果我所要做的就是右键单击命令提示符并选择以管理员身份运行来重新启动它。

I got this same error when running cl.exe from the Developer Command Prompt for VS2012 command window. Turned out all I had to do was restart the command prompt by right-clicking on it and choosing Run as administrator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文