C++ 链接:致命错误 LNK 1104:无法打开文件“LIBCMT.lib”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9356135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LINK: fatal error LNK 1104: cannot open file 'LIBCMT.lib'
提问by msknapp
Please help, I have spent all day trying to make my c++ app compile.
请帮忙,我花了一整天的时间试图让我的 C++ 应用程序编译。
My project contains one source file: Foo.cpp. Here is its code:
我的项目包含一个源文件: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;
}
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:
如您所见,我正在尝试使用 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'
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
包括: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
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.
我检查了 lib 目录,它包含一个“libcmt.lib”文件。不知道它是否区分大小写,但我知道我从未更改过 Visual Studio 文件或目录中的任何内容。
Would somebody please tell me how I can make this work?
有人请告诉我如何使这项工作?
回答by Alex Kremer
Resurrecting this thread in late 2018 since none of the other solutions helped my case :)
在 2018 年底恢复此线程,因为其他解决方案都没有帮助我的情况:)
For me this error started appearing out of nowhere after i installed Windows Driver Kitfor a completely unrelated project.
对我来说,在我为一个完全不相关的项目安装了Windows Driver Kit之后,这个错误开始突然出现。
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 Mitigationto Disabled.
如果您不需要“Spectre Mitigation”(您很可能不需要)并且看到此错误,很可能您只需要设置项目属性(属性页)-> 配置属性-> C/C++ -> 代码生成- >对残疾人的幽灵缓解。
Magically it was set to Enabledby 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.
神奇的是,它在所有项目中被 WDK 的 Visual Studio 工具安装程序设置为启用,即使它们与 WDK 无关,也没有为任何驱动程序相关的内容选择平台工具集。微软处于最佳状态。
回答by mrsheen
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.batbatch file.
要确保正确配置命令行环境,请确保您已运行vsvars32.bat批处理文件。
回答by Will I Am
Just to add my experience here, since it may help someone, and it applies to newer VS editions (2017 in my case).
只是在这里添加我的经验,因为它可能对某人有所帮助,并且适用于较新的 VS 版本(在我的情况下为 2017)。
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:
当我将项目移动到新机器时,我在编译过程中遇到了类似的错误。我终于发现我的依赖项中的一个项目打开了幽灵缓解功能,并且默认情况下不包含具有该支持的库:
回答by Mike
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.
如果您使用的 VS 版本不是您需要更改的版本。
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.
要更改 VS 的版本,只需将鼠标指针放在显示的当前 VS 版本名称的末尾并单击。
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.
这将打开一个包含 VS 版本列表的窗口。
Pick the version of VS you are NOW using.
选择您现在使用的 VS 版本。
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.
该窗口应该关闭,并且您的选择应该替换了我第一次构建时用于构建项目的旧项目 VS 版本。
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.
我希望这会有所帮助,它在处理使用早期版本的 VS 构建的项目时对我有用。
Good luck Mike.
祝迈克好运。
回答by slinkin
Right click on ProjectName(within Solution Explorer) -> Properties-> Linker-> General-> Additional Library Directoriesand set it like this:
右键单击ProjectName(在解决方案资源管理器中) ->属性->链接器->常规->附加库目录,并设置如下:
$(SolutionDir)$(Platform)$(Configuration)\;$(VCToolsInstallDir)\lib$(PlatformShortName);$(VCToolsInstallDir)atlmfc\lib$(PlatformShortName)
回答by Pflugs
I got this same error when running cl.exe from the Developer Command Prompt for VS2012command window. Turned out all I had to do was restart the command prompt by right-clicking on it and choosing Run as administrator.
从VS2012命令窗口的开发人员命令提示符运行 cl.exe 时,我遇到了同样的错误。原来我所要做的就是通过右键单击它并选择Run as administrator来重新启动命令提示符。