error can not open file in visual studio - c++

I am getting the error of :
error LNK1104: cannot open file 'ylmtr.obj' in visual studio 2013
In the properties of my project I made the following configurations:
Linker - Input - Additional Dependencies- ylmtr
V/C++ Directories - added to the directories of include, library, source their configurations from the program parser generator (used to create lexer to make a compiler)

https://msdn.microsoft.com/en-us/library/ts7eyw4s.aspx
To fix by checking the following possible causes:
Not enough disk space.
File does not exist.
When specifying libraries in a project's property pages dialog box, library names should be separated by spaces (and not commas).
Incorrect filename or path.
Invalid drive specification.
Insufficient file permissions.
Path for filename expands to more than 260 characters.
If the given file is named LNKn, which is a filename generated by the linker for a temporary file, the directory specified in the TMP environment variable may not exist, or more than one directory is specified for the TMP environment variable. (Only one directory path should be specified for the TMP environment variable.)
If the error message occurs for a library name, and you recently ported the .mak file from a previous Microsoft Visual C++ development system, the library may no longer be valid. Ensure that the library still exists in this circumstance.
Another program may have the file open and the linker cannot write to it.
Incorrect LIB environment variable. For information on how to update the LIB environment variable, see VC++ Directories, Projects, Options Dialog Box . Make sure any directories with libraries you need are listed here.

Related

Visual Studio deletes a shared .pch file, and questions about custom build steps

I try to use a shared .pch file, which is compiled in one project and used in others.
However the .pch file is deleted if a .pdb filename of the PCH project differs from .pdb filenames of the other projects.
This page doesn't answer the question: https://devblogs.microsoft.com/cppblog/shared-pch-usage-sample-in-visual-studio/
I don't want to use a same name for all PDBs.
Questions:
1) Why the .pch file is deleted at the start of other projects compilation, which leads to a C1083 error (.pch not found), if PDB names are not equal, not like in that page?
2) I copy pch.pdb and pch.idb files using COPY command, is there a RENAME comand or something, if the copied pch.pdb should be named just like a dependent project's PDB? And where can I find a complete list of Custom Build Step command?
3) I don't understand the purpose of "Additional dependencies" and "Outputs" in Custom Build Step. Can I enter the .pch filename into the dependency list, so it won't be deleted? Does the output list need to contain the dependent project's PDB name, or the pch.pdb, or both?
For some reason (I did this or not) the generated by compiler .pdb file was not $(PlatformToolsetVersion).pdb, but $(ProjectName).pdb . So the copied into other project folders shared .pdb file was pch.pdb in my case, while other projects were expecting different names. And that was triggering a DELETE task in Microsoft.CppCommon.targets , ("Delete the pch file if the pdb file has been deleted."). Instead of changing the output .pdb name I just looked into XCOPY command and made it to change the copied filename to an expected by a specific project (actually then I just added a custom Target with a renaming Copy task right into the project file instead of using the CustomBuildStep calling a xcopy OS's command, as now I learned more about MSBuild).
Then I also changed the generated by Linker output .pdb, just added "Linked" suffix to the name, so there are no conflicts between Compiler's and Linker's PDBs. Not sure if that is a good idea to change the default settings without a big reason.
I guess it's better just to change the Compiler's output PDB to $(PlatformToolsetVersion).pdb , so all projects will use the same name.
That was the first time I had looked into MSBuild and advanced project settings, now it seems to be obvious, that a project using a shared .pdb wants some familiar .pdb name, not a random pch.pdb
Here is my custom Target imported into project files copying the shared .pdb only if it was rebuilt (.idb is not generated in my case):
<Target Name="CopyFreshPchPdb" BeforeTargets="ClCompile"
Inputs="$(PchDir)\pch.pdb"
Outputs="$(IntDir)\$(ProjectName).pdb">
<Message Importance="High" Text="Copying shared pch.pdb" />
<Copy
SourceFiles="$(PchDir)\pch.pdb"
DestinationFiles="$(IntDir)\$(ProjectName).pdb">
</Copy>
</Target>
Did you use the sample code under the github link.
If so, you should download and then use that sample and if you create your own project, you should check your projects carefully.
Borrowing from this tutorial to your project, I think you need to pay attention to whether you have any additional custom targets in your xxx.vcxproj file to delete the PCH file. Therefore, you need to check each xxx.vcxproj file carefully. In vs, there will be no deletion of certain files due to the different .pdb file names of the PCH project and other projects, so check whether there are additional operations of your own.
1) Why the .pch file is deleted at the start of other projects
compilation, which leads to a C1083 error (.pch not found), if PDB
names are not equal, not like in that page?
First of All, make sure that there are no other option to delete PCH file in your projects.
The PCH project is to create a PCH file and the other two projects are to use such file. And every time when you build the two projects(reference the PCH project), and always execute the build of PCH project and then build the two project. So the PCH is always created and later be used in two projects.
Based on it, you should ensure that all three projects create and use the same address for the file.
SharedPCH project
ConsoleApplication1
ConsoleApplication2
In the sample code,the PCH file exists under SharedPchSample\Outputs\Intermediate\Shared\Win32\Debug.
2) I copy pch.pdb and pch.idb files using COPY command, is there a
RENAME comand or something, if the copied pch.pdb should be named just
like a dependent project's PDB? And where can I find a complete list
of Custom Build Step command?
Custom Build Step is under every project-->Properties-->Custom Build Step-->Command Line, and then you can find it.That custom step is just CMD command. And you can execute CMD in that to do extra opertion.
Besides, I guess you want to make those xxx.pdb and xxx.idb be the same name of the project name in order to distinguish one from another. You can right-click on every project-->Properties-->C/C++-->Output Files-->Program Database File Name-->change it and to use $(IntDir)$(ProjectName).pdb. More about Custom Build Steps, you can refer to this link.
I don't understand the purpose of "Additional dependencies" and
"Outputs" in Custom Build Step. Can I enter the .pch filename into the
dependency list, so it won't be deleted? Does the output list need to
contain the dependent project's PDB name, or the pch.pdb, or both?
Additional dependencies is set to use the PCH file's content in the project 1 and 2 which is similar to configuring the address of a reference class library in a c++ project. And I think it might be redundant and since the author has add it which implies that it is well-founded.
And Outputs is the author customized output path, the author changed the output address of the project, and started a new custom output path and a temporary output path.
Actually, the xxx.pch and its pdb and idb file will not be copied into outputpath. So the custom build step is to copied the files into temporary output path. And if you want to copied them into the final outputpath, you can also use these in CustomBuildStep.targets file:
<CustomBuildStep>
<Command>
if EXIST "$(SharedPdb)" xcopy /Y /F "$(SharedPdb)" "$(IntDir)"
if EXIST "$(SharedIdb)" xcopy /Y /F "$(SharedIdb)" "$(IntDir)"
if EXIST "$(SharedPdb)" xcopy /Y /F "$(SharedPdb)" "$(OutDir)"
if EXIST "$(SharedIdb)" xcopy /Y /F "$(SharedIdb)" "$(OutDir)"
</Command>
<Outputs>$(IntDir)vc$(PlatformToolsetVersion).pdb;</Outputs>
<Inputs>$(SharedPdb)</Inputs>
</CustomBuildStep>
And in fact, one project references another project, and the output files of the referenced project are automatically copied to the main project. Perhaps this is because the author's SharePCH project does not generate the pdb and idb files, so those files of the dependent project will not be found in the main project.
I'd like to add that I had a similar situation where a shared .pch file was being deleted but for a different reason related to the .pdb file.
The reason was that the pdb formats were different across the exe and the PCH.lib. The PCH library project has its 'Project Properties -> C/C++ -> General -> Debug Information Format' set to 'C7 compatible (/Z7)'.
When I added a new project exe that depended on the PCH library I had forgotten that new projects default to using 'Program Database (/Zi)' for its 'Debug Information Format'.
So now when the main project is being built and linked with the PCH it would delete the PCH.pch file and complain that the .PCH is missing.
Having all projects with the same matching Debug Information Format was the fix to prevent the PCH from being deleted.

fatal error: Eigen/Dense: No such file or directory in VSC

I am beginner-programmer and I wanted to run a code which includes “Eigen/Dense” library. However, I could not add this library into the Visual Studio Code (VSC). I followed the following instruction, but it did not work.
• Open command panel (Shift+CMD+P on OSX or Shift+Ctrl+P on Windows and Linux).
• Search for 'Extlibraries: Add external library' and press Intro.
• Input external directory or file path (here I entered the path of Eigen directory which I download from its website).
• Input name and press Intro (here I entered Eigen)
Could you please help me with this problem? I am waiting for your responses.
Thank you
Eigen is a header only library. That means that there is no library binary that needs to be linked. As such, you just have to make sure that the Eigen directory is correctly placed in your include paths. So, if you have the Eigen/Dense file is located at C:\some\path\to\Eigen\Dense, then the included path needs to be C:\some\path\to\.

Cannot compile resource for application manifest in C++ Builder 2006

I am trying to add the application manifest to a program built with C++Builder 2006, by following this article.
(The manifest is to obtain admin rights for my program, which contains "setup" in his name and so it triggers the “This program may not have installed correctly” warning).
I have the MyApp_Setup.exe.manifest in the project folder, along with the MyApp_Setup1.rc file, which is present in the project.
When i try to build, i get:
[RC Fatal Error] MyApp_Setup1.rc(1): File creation failed
What i'm doing wrong, or what should I do?
question edited 'cause i messed up the filenames and the output error didn't matched
Found the problem.
In the project options I always set an "_obj" output folder, but the resource compiler WANTS an existing "debug_build" folder to write the .res file.
It don't create the directory, hence the error in the file creation.
If i remove the "Obj" option, or once you have the "Debug_Build" folder present, everything compiles.

Linker outfile property file does not match targetpath?

I'm trying to compile a C++ type .DLL for a SierraChart custom study.
(Which is a financial trading application.) Here is the warning I get that I need to fix so it all points to the linker output value:
warning MSB8012:
TargetPath(C:\SierraChart\VCProject\Release\SCStudies.dll) does not match the Linker's
OutputFile property value (c:\sierrachart\data\SCStudies.dll).
This may cause your project to build incorrectly. To correct this, please
make sure that $(OutDir), $(TargetName) and $(TargetExt)
property values match the value specified in %(Link.OutputFile).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets
Any idea what's wrong?
I believe this warning appears specifically when upgrading a C++ project to VS2010. Visual Studio 2010 C++ Project Upgrade Guide describes some of the caveats encountered during an upgrade. If you're uncomfortable changing project settings, then retaining the older version of Visual Studio, may work for you.
To change the %(Link.OutputFile), open the project properties. Navigate to Configuration Properties -> Linker -> General. You can set the Output File to $(OutDir)\SCStudies.dll, which should take care of your issue. You may need to repeat the change for each Configuration/Flavor you will be building (Debug/x86, Release/x86, Debug/Itanium, etc...).
Based on this answer.
I changed the following property:
Linker -> General -> Output File to
"$(OutDir)$(TargetName)$(TargetExt)"
This prevented the warning to appear and the output was generated successfully.
The original configuration was set like:
Properties -> Linker -> General : $(OutDir)\"<'name fileA>".exe
The program tries to run "<'name_project>".exe and as result error Linked.
You need to set the configuration as:
Properties -> Linker -> General : $(OutDir)\"<'project name>".exe
A different fix which others haven't mentioned is that by default the TargetExt is .exe and for my debug builds I changed it to be _d.exe, where instead you should be doing that in the TargetName path.
The directory specified in General->Output Directory and the directory specified in the path at Linker->Output File have to match.
If you want to change the defaults do things in these order:
You first configure the OutDir in General->Output Directory. E.g.
$(SolutionDir)$(Platform)\$(Configuration)\MyProgram\
Make sure Output File is consistent. E.g. this would work
$(OutDir)\$(TargetName)$(TargetExt)
The comment from Gerardo Hernandez helped me.
The directory specified in General->Output Directory and the directory specified in the path at Linker->Output File have to match.
In my case I was importing a large project from Visual Studio 6 and
C:\Project\myproject\OneOfMyDlls\.\Debug\OneOfMyDlls.dll
was not equal to
C:\Project\myproject\Debug\OneOfMyDlls.dll
but
C:\Project\myproject\OneOfMyDlls\..\Debug\OneOfMyDlls.dll
would have been, after path reduction.
The problem was that the Visual Studio 2017 import had changed the output directory from
..\Debug to .\Debug assuming that the unconventional parent directory use was a mistake. In a large project with 13 DLLs of our own, (never mind second and third party DLLs too), it makes sense to collect all the DLLs in one place and ..\Debug was correct.
So while others might have had to change Linker->Output File, in my case it was General->Output Directory which needed to change as it had been corrupted by the import from Visual Studio 6.
Something like ..\Debug had become something like .\Debug after import. (The real project specific names have been removed .)
Looks like it's not significant for the program:
Odd Visual Studio error when following the custom study video
If, like me, you return to Visual Studio after 20 years, you may not know where the project properties are. In VS 2012: top of the screen "FILE EDIT VIEW PROJECT BUILD..." : choose PROJECT. Properties is the last item in the menu. Indeed for me there was a mismatch in the target name, too.

Why does visual studio ignore the tlb filename specified in the project file

I'm in the process of upgrading a Visual C++ 6 project to Visual Studio 2010, and I've been replacing the post-compile steps of copying files to a common location with having the output file put directly in the final location. However, for the *.tlb files that are being generated, there is an option (in project properties -> MIDL -> Output) to specify the filename. When I put the full path there, it looks reasonable in the command line (says /tlb "full\path\to\filename.tlb"). However, when it actually compiles, the file doesn't get put in the right place, and the command that was executed according to the log was /tlb ".\filename.tlb"). I'm hesitant to specify the path as the output directory, because then it will output the XXX_i.c and XXX.h files into that location as well, which isn't what I want.
Is there any way to get Visual Studio to respect the setting I actually put in the option, instead of doing what it wants?
I just had this problem as well and I finally found out why. Even though this question is a bit old, since it's still open I'll post my solution...
In addition to the MIDL settings under the project properties, there's the same settings under the IDL file itself. Just right-click the IDL file -> Properties -> MIDL -> Output.
This did it for me. Seems illogical, though.
I also ran into same situation so I specified the output file as a relative path and it generated the tlb file in the correct location instead of the default location