Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio C++/CLI Mysterious Error With Template

Well, I've been trying to make a C++ DLL in Visual Studio 2015, which took a while since I'm not very good with Visual Studio.

I need to access the .NET libraries, specifically System::Management. (Writing the code was a little harder than it needed to be due to a poor C++ implementation, but at least it has one.)

I fixed obvious errors and finally figured out I had to enable CLR in the project properties and then select the related libraries with References->Add Reference. But after all that, now it's just giving this weird error:

LNK1104: cannot open file 'MSCOREE.lib'

The compiler doesn't show red wavy lines below anything, and the error claims the line is "1" and the file is "LINK", so no help there.

I thought I probably messed up the project configuration somewhere, so I created a new project and moved the code over. The error still happened. If I turned off CLR and commented out the .NET-dependent code, the build succeeded without errors.

So I tried creating a new project from template (Visual C++ -> Win32 Console Application) and then enabling CLR before doing anything else. Then I tried again, selecting different versions of .NET framework.

Finally, I tried creating a project with template (Visual C++ -> CLR -> CLR Console Application) and building it immediately. I mean literally without doing ANYTHING ELSE. It still gave the same error!

LNK1104: cannot open file 'MSCOREE.lib'

What on earth is going on? Am I doing something wrong here, or is VS2015 just broken?

like image 675
Pecacheu Avatar asked Dec 08 '16 02:12

Pecacheu


4 Answers

I had the same problem. Installing ".NET Framework 4.6.1 SDK" solved the problem. Pay attention to the version number, take it from your project configuration files

like image 121
Greg Avatar answered Nov 14 '22 20:11

Greg


Check in Visual Studio installer 'C++/CLI support' for build tools of your needed version.

like image 21
Sergei Krivonos Avatar answered Nov 14 '22 20:11

Sergei Krivonos


Try this, Right click the project that shows 'LNK1104: cannot open file 'MSCOREE.lib'', then select Properties --> Configuration Properties --> VC++ Directories --> Library Directories --> Add both entries from below separated by semi-colon

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64

This is where your 'mscoree.lib' should be, check if its there before doing this otherwise you might need to install/reinstall the Microsoft SDKs

like image 1
Jay Avatar answered Nov 14 '22 20:11

Jay


In some situations the SDK may not install the required files in the LIB folder as described in MSCoree.lib missing from WinSDK. Their solution was to execute a repair of the install. That may not work.

I have successfully ran WinSDKInterop_amd64\WinSDKInterop_amd64.msi resulting in the creation of:

C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\IA64\mscoree.lib
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\mscoree.lib
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64\mscoree.lib
like image 1
Jason Pyeron Avatar answered Nov 14 '22 18:11

Jason Pyeron