问题描述
请帮忙,我花了一整天的时间来编译我的 C++ 应用程序.
Please help, I have spent all day trying to make my c++ app compile.
我的项目包含一个源文件:Foo.cpp.这是它的代码:
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;
}
如您所见,我试图使用 JNI,但我认为这与问题无关.这是我在命令行上尝试的:
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:Usersmichaelcworkspacefoo>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:
包括:C:_include;C:frankensteinincludes;C:Program FilesJavajdk1.6.0_24include;C:Program FilesJavajdk1.6.0_24includewin32;C:_includewin32;C:Program Files (x86)Microsoft Visual Studio 10.0VCinclude
INCLUDE: C:_include;C:frankensteinincludes;C:Program FilesJavajdk1.6.0_24include;C:Program FilesJavajdk1.6.0_24includewin32;C:_includewin32;C:Program Files (x86)Microsoft Visual Studio 10.0VCinclude
库路径:C:Program Files (x86)Microsoft Visual Studio 10.0VClib
LIBPATH: C:Program Files (x86)Microsoft Visual Studio 10.0VClib
我检查了 lib 目录,它包含一个libcmt.lib"文件.不知道是否区分大小写,但我知道我从未更改过 Visual Studio 文件或目录中的任何内容.
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?
推荐答案
在 2018 年底重新启动此线程,因为其他解决方案都没有帮助我的情况 :)
Resurrecting this thread in late 2018 since none of the other solutions helped my case :)
对我来说,在我为一个完全不相关的项目安装 Windows Driver Kit 后,这个错误开始突然出现.
For me this error started appearing out of nowhere after i installed Windows Driver Kit for a completely unrelated project.
如果您不需要Spectre Mitigation"(您很可能不需要)并且看到此错误,则很有可能您只需要设置项目属性(属性页)-> 配置属性 -> C/C++ -> 代码生成 -> 幽灵缓解到禁用.
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.
神奇的是,它被所有项目中用于 WDK 的 Visual Studio 工具的安装程序设置为启用,即使它们与 WDK 无关,也没有为任何驱动程序相关的内容选择平台工具集.微软处于最佳状态.
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.
这篇关于链接:致命错误 LNK 1104:无法打开文件“LIBCMT.lib"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!