C++ code library open error in Visual C++ - c++

I am beginner developer in the VC++ environment. I used C++ code under the VS 2012 for NUnit Testing.
I was trying a code in the test project but it keeps generating an error that a library file is not being opened. I checked in the project properties and there is a library named: Microsoft.VisualStudio.TestTools.CppUnitTestFramework.lib
but it still generats an error
LINK : fatal error LNK1104: cannot open file 'Microsoft.VisualStudio.TestTools.CppUnitTestFramework.lib'
Does anybody solved such problems before or you remmend me to do ?

Yes, I had this Problem too. I am working on VS express 2013, and I had created a new unit for an unmanaged dll and a test unit, which refers to.
To overcome,
I found out, where the named CppUniTestFramework.lib is. It is not, where your VS Project files are.
I found it under C:\Program Files(86)\Microsoft Visual Studio 12.0\VC\UnitTest\lib
I navigated to the file in Windows Explorer, copied the pathname out of properties and added this in Unit test Project properties under
Linker - > Allgemein -> zusätzliche Bibliotheksverzeichnisse (Linker - > General - > Additional Library Directories).
I feel, this is not a nice solution, but it works now. I see now my first unit tests running.

Related

visual studio 2019 - C++ cannot open source file

I am using Microsoft Visual Studio Community 2019 Version 16.8.4 on a Windows 10 machine.
I have established that my include files live in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" because I can actually see them listed there. However, I get an error with the line #include <cstdio>.
I have tried right click on project name to bring up a context from which I chose 'Properties'. From the "Solution Project1 Property Pages", I selected "Debug Source Files" and then entered the full directory path to the include files.
I still get the error
You need to add the directory where the headers are found to the project properties under either C/C++ -> Additional include directories or VC++ -> Include directories.
And note that you need to make sure that the directory is added for all project configurations/platforms you wish to be able to build. The Debug source files item is only so that files can be found when running the debugger and have nothing to do with the project build stage.
I ran Visual Studio Installer and noted that one of the workloads, 'Desktop development with C++' had not been activated. After activating it and downloading the required or missing binaries, I am now able to create an empty project using an example of the quintessential 'Hello World' program such as #include int main(){printf("Hello, world");return 0;}
#include <cstdio> is part of the C++ Standard Library headers, if you are getting the error E1696: 'cannot open source file, you might have to retarget the solution/project. Do the following:
Right-click the Solution in the Solution Explorer pane;
Retarget solution;
Follow the steps/press OK.
It worked for me when I couldn't find Standard Library headers, hopefully, it works for you as well.

Fatal error “LNK1104: cannot open file 'libCbc.lib'” when I compile a C++ project in Visual Studio 2017?

I've never used VS before.
My friend shared with me his program working and running correctly (she uses VS 2013 and I use 2017 - any compatibility problem?).
I've downloaded it and changed the paths on
Configuration Properties, C and C++, General, Additional Include Directories (picture below)
Configuration Properties, Linker, General, Additional Library Directories
However Im getting one fatal error which does not find this file located in:
Users\Julio\Documents\CPFL\SolverCPP\coin\libdebug
Users\Julio\Documents\CPFL\SolverCPP\coin\lib
How can I solve this path error? Also any tip to share project is welcome,

Microsoft Visual Studio 2013 Link Error 1104

A while ago I attempted to make make a game using c++ and SDL. I am now taking a class that requires me to program in C++ and I would like to use VS as the IDE. I uninstalled VS 2012 and upgraded to 2013. I am able to compile c# code but when I make a c++ project I get the error
error LNK1104: cannot open file 'SDL.lib'
I went to the project properties -> Configuration Properties -> Linker -> input and made sure that SDL was not referenced there. My Additional Dependencies now has the value %(AdditionalDependencies). The rest of the options are blank. I also made sure that in VC++ Directories the Include Directories did not include anything related to SDL. Having done all of this I still get the same error. Is is somehow inheriting the SDL linker. The project only contains a hello world program which does not include any other libraries. Any help is appreciated.
You can try this:
Right click the project and choose Properties.
Open Configuration Properties --> Linker -->Input.
In the Ignore Specific Default Libraries entry, add SDL.lib.
BTW, whatever you add in your Include Directories cannot cause a linkage error (and neither can any include that you have in your project).

Using fuzzylite in Visual Studio 2010

Has anyone done this before ? I am not able to get it to work.
Following are my steps:
Download the windows package from link
I can run qfuzzylite (gui-tool) without any problem. Now I want to use the fuzzylite lib in my Visual Studio + Qt Integration Project.
In the CMake GUI I give fuzzylite source folder as the input folder and select Visual Studio 2010 as the compiler.
I am able to generate the Visual Studio fuzzylite solution in CMake without any errors.
Then, I tried to build the Visual Studio solution, but it fails with some weird errors. However, it does generate the fuzzylite-dbg.lib file (which I need).
Then I use this lib file and the fuzzylite.dll and include the path to the Headers in the VS Project. The project builds without any errors.
Now in the code I am doing
fl::Engine* engine = new fl::Engine("simple-dimmer");
This fails with the following exception:
exception text: bad allocation
exception type: class std::bad_alloc
Thank you for your detailed steps, but the solution seems to be a bit random (or weird as you put it). Unless more information is provided about the error, I strongly discourage the use of such a solution to attempt any fix to fuzzylite.
If you are running into problems, I strongly encourage you to report the problem in the forums at http://www.fuzzylite.com, where I and others will be very happy to help you.
As for the compiling errors, fuzzylite treats warnings as errors. A warning that is being raised in fuzzylite 4.0 when compiled using Visual Studio (not from console via nmake), and potentially in previous versions, is warning C4702, which refers to unreachable code. You can fix this by adding in file fl/fuzzylite.h the following line within the #ifdef FL_WINDOWS (together other #pragmas):
#pragma warning(disable:4702) //Ignore unreachable code
If the library was not built correctly, errors are bound to happen during runtime.
Ok, got it :)
Here are the steps for future reference:
Download the windows package from link
In the CMake GUI I give fuzzylite source folder as the input folder and select Visual Studio 2010 as the compiler. Now, if you want to use the lib in Debug mode tick the FL_DEBUG box (this is where I went wrong)
Now on clicking "generate", it will generate 5 projects:
ALL_BUILD
fl-bin
fl-shared
fl-static
INSTALL
ZERO_CHECK
Now in the Project properties in fl-bin, shared and static go to the Project Properties. In C/C++ go to Preprocessor get rid of the space in FL_DATA="mm.dd.yyyy " to "mm.dd.yyyy" (weird).
The solution should build fine and will generate fuzzylite-dbg.dll and fuzzylite-dbg.lib in the lib folder.
Use these files in your VC Project by adding the fuzzy-dbg.lib as the linker input and place the dll in the solution folder. Give the path "path\to\fuzzylite\fuzzylite." to the Include Directories.
Do the same process for Release mode (don't tick the FL_DEBUG flag)

LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'

I'm a novice C++ developer. I encontered the error message indicates "LINK :fatal error LNK1104: cannot open file 'MSVCRTD.lib'" while I'm trying to debug every single project in Microsoft Visual C++ 2010 Express. I searched on Stack overflow and Google for any possible resolution, but I couldn't find exact and precise answer. What I have understood is that the "msvcrtd.lib" file should be in "\Microsoft Visual Studio 10.0\VC\lib", but that file is not there in my case. What should I do?
For the poor souls out there who are struggling with this, after an hour of research I found a solution for my Visual Studio Enterprise 2017:
First, lets find where is your library file located:
With windows explorer, go to your directory where Visual Studio is installed, (default: C:\Program Files (x86)\Microsoft Visual Studio) and do a search for msvcrtd.lib
I found mine to be in here:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\lib\onecore\x86
Quick Fix (for one project only):
Right click on your project, click on properties, navigate to Linker, add that path to Additional Library Directories
Permanent Fix (for all projects)
Open a project
navigate to View > Property Manager (it could be under Other Windows)
Expand all folders and multi select all "Microsoft.cpp.Win32.user" & "Microsoft.cpp.64.user"
Right click and go to properties
Navigate to VC++ Directories
Add the path to default Library Directories
Go to your project properties, select Linker from left. Add this to "Additional Library Directories":
"(Your Visual Studio Path)\VC\lib"
For example:
C:\Program Files\Microsoft Visual Studio 10.0\VC\lib
I came across this problem when compiling a sample app using VS2017
Hope this will help
There is a check box that says "Inherit from parent or project defaults" in some of the property dialogs in Project Properties. Make sure that check box is checked for your Include and Library directories property windows and of course for your Additional Dependencies window.
If you use VS2017, please read it. Or just ignore this answer...It may be invalid for other VS version.
Do not trust anyone who told you to add lib path.
Here's suggestions:
[BEST] You just need to install these via VS_installer (most of us just need x86/x64 version below)
VC++ 2017 version version_numbers Libs for Spectre [(x86 and x64) | (ARM) | (ARM64)]
Visual C++ ATL for [(x86/x64) | ARM | ARM64] with Spectre Mitigations
Visual C++ MFC for [x86/x64 | ARM | ARM64] with Spectre Mitigations
[NAIVE] or disable Spectre Option for every Solution
(Why We are so hard to global disable it)
[LAUGH] Or never use VS2017
This is VisualStudioTeam's fault and Microsoft is guilty.
Why?
You can't make a global configuration to disable /QSpectre, and IDK when and why VS2017 enable it in one day. So the best way is install Spectre? ahhha?
For VS 2019, Spectre Mitigation is enabled by default.
So the right way to fix the issue would be to install VC++ Libs for Spectre.
But, to quickly resolve the issue, you may disable Spectre Mitigation
Project Properties -> C/C++ -> Code Generation -> Spectre Mitigation -> Disabled
https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
I ran into this issue. The file existed on my machine, it was in the search path. I was stumped as the error result is really unhelpful. In my case I had turned on Spectre mitigation, but had not downloaded the runtime libs for Spectre. Once I did the download all was right with the world. I had to get this installed on my CI build servers also, as these libs are not installed with VS by default.
I have solved this problem, you need install all spectre lib.
Vistual Studio Installer->Modify->Component->Any spectre lib.
This solution can be adapted to any project.
For me this issue happens after installing the (Windows Driver Kit): https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
Uninstalling it fixes the problem. Just posting here as a related issue for people looking for solutions: After installing WDK VC++ is broken
Scenario:
Windows 10 with Visual Studio 2017 (FRESH installation).
'C' project (LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib').
Resolve:
Run 'Visual Studio Installer'.
Click button 'Modify'.
Select 'Desktop development with C++'.
From "Installation details"(usually on the right-sidebar) select:
4.1. VC++ 2015.3 v14.00(v140) toolset for desktop.
Version of 'toolset' in 4.1. is just for example.
Click button 'Modify', to apply changes.
Right-click 'SomeProject' -> 'Properties' ->
'Linker' ->
'General' ->
'Additional Library Directories': $(VCToolsInstallDir)\lib\x86
(!!! for x64 project: 'Additional Library Directories': $(VCToolsInstallDir)\lib\x64 !!!)
it is also worth checking that MSVCRTD.lib file is present in "C:\Program Files\Microsoft Visual Studio 10.0\VC\lib" for x64 and in C:\Program Files(x86)\Microsoft Visual Studio 10.0\VC\lib for 32 bit. Sometimes VS might not be installed properly OR these files might get deleted accidentally.
I just had this error, in my case rebuilding the project while doing nothing else worked for me.
Here's my situation
Visual studio crashed and I had to re-install and my new installation path is different than the previous one. then I had this error
the error showed that the library is located at
D:\program\Microsoft Visual Studio\...
while it should be
D:\program files\Microsoft Visual Studio\...
as I said I just rebuilt it and it worked for me and if you have a multi-solution project you have to rebuild the whole-solution
I solved the problem by adding #using <mscorlib.dll> in the main file
This indicates that Visual Studio wasn't able to find the lib (Library) directory which contains msvcrtd.lib.
IMPORTANT: This lib directory also contains linkers required during the compilation process.
So, all you need to do is override the Library Directory location. You can do so with the help of Environment Variables.
I referred to this StackOverflow Post for help. As per the answer posted, the Environment Variable LIB refers to the path where the Linker Libraries are located. Why is this method better? Because this will apply to all the projects instead of just a particular project. Also, you don't need to download anything extra. It just works...
Follow the steps below to achieve this:
STEP-1: Search for "msvcrtd.lib" in the search bar.
STEP-2: Click "Open File Location" (available in context menu)
STEP-3: Copy the address of the directory from the address bar.
STEP-4: Search "Environment" in the taskbar and click on "Edit the system environment variables".
STEP-5: Click on "Environment Variables..." button.
STEP-6: Under "System variables" section, click on "New..." button. A dialog would pop up.
STEP-7: In the dialog box, enter the following:
Variable name: LIB
Variable value: [The directory you copied in "STEP-3"]
And press "OK"
Now, you are all done!
The above answer was not quite accurate for me. I have VS2010 Ultimate installed and the file in question is not in my Visual Studio 10.0\VC folder. Rather I found it in the Visual Studio 9.0\VC folder. So if that's the case for anyone, follow the lead to change the Linker but use the Visual Studio 9.0\VC folder instead. It worked for me.
For Visual Studio 2017
Go to your project properties, select Linker from left. Add this to "Additional Library Directories":
C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\lib
I got a slightly different error
LNK1104 cannot open file 'MSVCURTD.lib'
Note it is msvcUrtd (not msvcrtd), but the file is not found on my system.
Solved it by setting the following options:
Project Properties
General
Character Set: Not Set
Common Language Runtime Support: Common Language Runtime Support (/clr)
Hope that helps.
In VS2017 (Community/Enterprise/Ultimate/Professional):
Add the path(s) of the folder(s) which include your desired ".lib" file(s) in the following path in VS:
(Right Click)Project(in Solution Explorer)->Properties->Configuration Properties->Linker->General->Additional Library Directories
If there are more than one ".lib" file use ';' to separate them otherwise click on the edit box corresponds to "Additional Library Directories" then click on "" in drop down menu and add all desired ".lib" files in newly opened window one by one and in a easy to handle manner.
I ran into this using Visual Studio 2017. I tried the solutions suggested here with explicitly adding paths to where the 'MSVCRT.lib' file was located. But I felt this probably wasn't the correct approach because previously for the past several weeks this had not been a problem with my project.
After trial and error, I discovered that if I left an empty or blank value in the Linker --> Input section, it would give me the error about LNK1104: cannot open file 'MSVCRT.lib'. Eventually I figured out that I should leave this value there instead.
On the Visual Studio project, right-Clicking on the project item in the Solution explorer panel (not the Solution itself, which is the topmost item), then select Properties. From there do the following:
Linker --> Input : %(AdditionalDependencies)
This additional information might be helpful, if you got into the situation the same way I did. I have discovered that I should not put any non-system library paths in the Linker --> Input section. With my project I was trying to compile with external .lib files. Previously I had a value in this input section like: $(ProjectDir)lib; %(AdditionalDependencies) but this lead to other problems. I discovered the correct place (it seems so far) to put paths for referencing external .lib files in a C/C++ project in Visual Studio 2017 is here:
VC++ Directories --> Library Directories : $(ProjectDir)lib; $(LibraryPath)
Note the $(LibraryPath) value will include extra values such as inherited from parents. My folder project contained a folder called 'lib' which is why I had the first value there before the semicolon.
I have included the following path
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86
and
C:\local\boost_1_64_0\lib64-msvc-14.1
To
project properties-> linker-> Additional Directories
Click here : Image shows linking of boost and MSVC2017