Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINK: fatal error LNK 1104: cannot open file 'LIBCMT.lib'

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?

like image 867
msknapp Avatar asked Feb 20 '12 04:02

msknapp


2 Answers

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.

like image 145
Alex Kremer Avatar answered Sep 30 '22 00:09

Alex Kremer


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.

like image 29
mrsheen Avatar answered Sep 30 '22 00:09

mrsheen