Visual Studio 2010 C++/CLI in Static Library Mode: could not find assembly 'mscorlib.dll' - visual-studio-2012

I am working on a C++/CLI project with VS 2012 in Dynamic Library (.dll) and x64 mode.
If I switch the mode to Static Library, I get the error below.
Error 1 error C1107: could not find assembly 'mscorlib.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable C:\Depot\Main\Current\Sln\ALibraryProject\Stdafx.cpp 1 1 ALibraryProject
I tried removing the reference to the mscorlib.dll then adding it again from:
Project > Properties > General > Common Properties
But that didn't help. As I know that VS handles the reference to the .NET assemblies, I don't want to add a disk file reference to it as it seems illogical! Did anybody face this before?

I had the same problem when converting my solution from the VS2010 compiler to VS2013 compiler.
I resolved it by changing the project settings (for the project containing the managed .cpp file that was throwing this error) as follows: In Project Settings | C/C++ | General | Additional #using Directories I added the macro $(FrameworkPathOverride). This resolves to the reference assembly directory for the version of .NET that you're targeting, which in my case is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1

If I switch the mode to Static Library
This is not the typical error you get when you try to build a static library with /clr in effect. I'd have to assume you've been tinkering with project settings to get rid of the inscrutable linker errors you get when you try to do this.
Core issue is that the C++/CLI build system doesn't support static libraries that contain MSIL. Managed code doesn't use a linker, binding happens at runtime. Which makes the essential difference between static libraries and DLLs disappear. So Microsoft decided to not support it because it didn't make much sense to implement it. Unfortunately they don't yell loud enough when you try to do it anyway, the linker errors you get don't give enough of a hint what you did wrong. Workarounds, like merging with ILMerge don't work either, it cannot deal with mixed-mode assemblies. Merging the native code sections and their associated relocation table entries is very untrivial.
Keep in mind that it is fine to link native static libraries. A typical C++/CLI project has only the ref class wrappers that need to be built with /clr in effect. You can glue any amount of native code from libraries into the final assembly.
I'm forced to theorize about the actual compile error, too many programmers get this error for another reason that doesn't have anything to do with building static libraries and they are harassing me in the comments.
Do beware that targeting a different version of .NET than the one you have installed on your machine is quite a hazardous affair, particularly so if you want to target 4.0 and you have 4.5.x installed. The key element in your .vcxproj file is the <TargetFrameworkVersion>. This will be missing if you started the project targeting an old .NET version, you have to insert it yourself. The IDE also doesn't support changing it if it is present, again edit by hand.
Which is enough to coax MSBuild into generating the proper compile command. You can verify if that panned-out well, look in the *.tlog subdirectory of the Debug build directory for your project. The cl.command.1.tlog file shows the options that were passed to the compiler. It should contain:
/AI"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0"
/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll"
Note the subdirectory, very important that it matches your intended .NET target. v4.0 in this example. And very, very important that it does not point to c:\windows\microsoft.net, the legacy location for reference assemblies.

I have the same problem. Having a dll doesn't work, as I need to provide a native C++ wrapper for a .net object so it can fulfil a natice c++ interface - I can't use .net in a dll interface - this gives a compile error
This worked as a static library in VS 2010 (with .net 4)
Some of my executables and dlls which also have some code with /clr. They don't have an issue. I'm not trying to make a net Lbirary.

I solved it by removing dependency in old and not updated mixed lib, which was also configured only in Debug configuration, and as result, it started to get the same error as yours after I changed some code.
It was not simple to find it, because error is not clear, and the dependency was set up via "Additional Dependencies" in project settings.

Open visual studio and unload your project then Go to the project folder and open file .vcxproj . Search for tag "targetFrameworkVersion"
(if not present it means ur project is not using dot net frameworks.so no requirement of change)
Change it to required version
Save the file.
And now reload the project .

Related

Visual Studio 2015 code map external dependencies

I have a native Win32 project written in C and wanted to visualize my project's dependencies from external DLLs. Visual Studio 2012 and 2013 let me generate a code map which would not only show all my functions and their dependencies from each other using arrows, but also all external libraries I used, which functions I used from those and which of my functions called which external functions etc..
Now, in Visual Studio 2015, this latter part seems to be missing. I can not get Visual Studio to show my project's external dependencies. I only see the internal ones. So here's my questions: Am I missing something? Do I have to activate a specific option in my project settings? Or are those external dependencies just not working in Visual Studio 2015 right now?
Steps to reproduce: Create a new non-empty Win32-project. In the Architecture menu, select Generate code map for solution. You will only see Win32Project1.exe in the middle of the screen. Meanwhile, Visual C# seems to be fine, showing the external dependencies. Create any C#-project for comparison.
Thank you for taking the time to post this! This looks like a regression, as in Visual Studio 2013 an Externals group with external dependencies is shown for C++.
I've logged a bug on Microsoft Connect so that you're able to track this externally:
https://connect.microsoft.com/VisualStudio/feedback/details/1694695
I have posted this workaround on the link that Bogdan Gavril listed and hope it helps someone. Unfortunately, it requires that you enable "CLR" support for your project. Basically, it appears that the VC++ linker and librarian is looking for a flag that indicates some type of managed code. At the very least, the code map is dependent on the mscorlib.dll reference injection. To make the CLR issue (which adds a lot of unnecessary bulk for native code) less a problem, simply create a new build configuration for use only when you need code maps with external dependencies. Make sure you've selected "CLR Support" on the general options of the project properties configuration page. Then, clean (probably not necessary) your solution and generate a code map. You will find the external dependencies as expected!
Zac

Missing .dll error reoccurence

I have a question regarding VC++ 5.0.
For a dialog-based project I am writing, I have linked it to a particular dynamic link library called File32.dll by adding the corresponding .lib file to my project debug folder as you do.
I also linked to this library in the Project Settings. This library contains functions specific to a particular application which I need to access. All of the necessary header files have been included and the project builds without errors or warnings.
The problem is that once I try to debug and run the dialog, an error appears:
The program can't start because OUTPUT.dll is missing from your
computer.Try reinstalling the program to fix this problem.
OUTPUT.dll is a library I am not linking to for this project. And when I add this particular .dll to my debug folder, the same error appears with a different .dll (SYSINT32.dll).
No matter how much I add these dlls to my debug folder, the error message reappears with a new dll. Bare in mind, the project debugged and ran successfully before I linked to File32.lib. So I feel that the problem lies with File32.lib. Any ideas on what might be happening with the linker?
Use Dependency Walker to open your File32.dll. It will show all DLLs this one (statically) depends on. It will also highlight the missing ones.
As for VC++ 5.0 ... I feel the need to comment ...
Visual C++ 5.0, which included MFC 4.21 and was released 1997-04-28 (...)
that's an amazing 18 years :-)

Orchard off the shelf and no joy

Just grabbed the latest .zip release of the orchard CMS from http://orchard.codeplex.com/releases/view/65184 and have opened this via VS2010 by pointing
at the extracted folder.
When I attempt to compile I get the following error:
The type or namespace name 'Blogs' does not exist in the namespace 'Orchard' (are you missing an assembly reference?)
Any thoughts?
You need to either:
download the recommended download and run that directly without compiling. It simply does not have what's necessary to recompile everything. It only knows how to dynamically compile modules and themes at runtime.
download the full source code and compile that in VS
If you are going to use VS, I highly recommend you use the full source code.
I'm not sure what's in that zip but if this is ur first look at orchard, try using webmatrix. It's fairly painless.
Orchard is not a conventional mvc app. It has a core needs to be compiled but the modules are compiled at runtime. If the core isn't compiled in that zip you'll need to open the project from the sln file in visual studio. If it is compiled you might need to setup the web directory as a virtual directory in iis.
I found it easier to familiarize myself with orchard in webmatrix first. There is enough in that to keep u busy for a bit!
Hope that helps

Linker warning C++ Visual Studio

I have run into this problem, which although is a warning, I suspect is a sign of something wrong under the hood. When I build in release mode I get this warning:
MSVCRT.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
I'm building a dynamic DLL in Visual Studio C++ Express Edition. When I do it in debug mode no warning arises. I've googled a bit and it looks like msvcrt and msvcrtd are both for multithreading, one for debugging and the other not. I could use /NODEFAULTLIB with MSVCRT.lib, but I don't think that avoiding symptoms really helps with the problem.
I really don't know if this is a huge problem. The DLL and .lib files are generated correctly.
Check that your runtime library settings are correct in the Release configuration of your project. Basically it should be the same as your Debug build, but without the word 'Debug' in the description. Visual Studio docs on this issue are here.
Check your settings as follows:
in Solution Explorer right click the Project and select Properties
make sure the Configuration (at the top of the Properties window) is Active (Release)
go to Configuration Properties -> C/C++ -> Code Generation
check that Runtime Library for Release is not a Debug version of the CRT.
The problem is related to your libraries.
They are linked differently than your program.
Your program may be single-threaded, while your libraries may be linked as multithreaded, for example.
Look under
Project Properties
Configuration Properties
C/C++
Code Generation
Runtime Library
to see the setting (e.g. "Multi-threaded Debug DLL (/MDd)").
This is a huge problem, since it can lead to many unexpected crashes of your application, AND you can't distribute an application which links msvcrtd.lib, since you are not allowed to distribute the debug C++ runtimes of Visual Studio.
Though /NODEFAULTLIB should fix those, you should fix the issue itself.
Like casablanca said, msvcrtd.lib is linked in release mode, but it should only be linked in debug mode.
This does not mean that your own application has wrong linker settings. Any of the libraries you use in your project could have incorrect settings as well.
What I usually do to fix this is, to open all the release .lib files which your application links, with a text editor which can open such large binary files (like SciTE), and then I search them for e.g. VC80.DebugCRT (VC80 == Visual Studio 2005 in this case), and if I find this string in one of those libraries, that library should be recompiled with /MD.
If you are linking dynamic libraries, you can use a tool called Dependency Walker on the .dll files instead of manually searching the .lib files.
If Dependency Walker shows the dependency on one of the debug crt DLL files like e.g. MSVCP80D.dll (note the trailing D), recompile that library using /MD.

How to make project exe,how to include all runtime dll files

How to include the windows runtime dll files in setup project.
without vc++ 6.0 software in the machine the project must execute.
or give me the hint how to make a the project setup(EXE) in vc++ 6.0 ,i am using create installor,
You can modify the project settings to link statically to the C runtime (I assume this is what you mean when you said windows runtime ?). The static link flags are:
MultiThreaded static linkage (/MT)
MultiThreaded debug static linkage (/MTd)
Sorry, been awhile since I used VC6.0, so I had to check the GUI. You'll find this in project settings, C++ tab, Code Generation combo box, "Use run-time library").
To add to what Cannonade has already said, if you are doing it through Visual Studio, then this can be done through Project Settings->General Page->Use MFC as a static library. This way your created exe will be ready to run on any windows box.

Resources