Why won't my generated .sln file open in Visual Studio 2010? - c++

I'm dealing with a fairly large C++ code base. The code base is normally intended to be compiled under Linux, using custom build scripts and makefiles. I'm porting the code into Visual Studio, which as anyone who's used Visual Studio would agree, is a pain to do manually.
My own looking has been kind of fruitless, so I started writing my own utility in Qt to analyze the codebase and generate a solution file and accompanying .vcxproj files. I've been using the QUuid class to generate GUIDs for each of the projects, and I'm using QTextStream to write the .sln file.
Now, here's the problem: When I open the generated .sln file, I see the following errors.
I'm currently trying to generate a solution that I've already manually created within the Visual Studio IDE. I've compared my generated .sln file against the the one Visual Studio created, and apart from the projects appearing in a different order and the GUIDs not matching (obviously), I can't spot a difference. I'm including a simplifed example of my problem here.
Visual Studio generated this:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mylib", "mylib\mylib.vcxproj", "{35BAFEEE-35FA-4313-AF67-AF8AB7458451}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Debug|Win32.ActiveCfg = Debug|Win32
{35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Debug|Win32.Build.0 = Debug|Win32
{35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Release|Win32.ActiveCfg = Release|Win32
{35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
And I generated this:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mylib", "mylib\mylib.vcxproj", "{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Debug|Win32.ActiveCfg = Debug|Win32
{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Debug|Win32.Build.0 = Debug|Win32
{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Release|Win32.ActiveCfg = Release|Win32
{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Here are my questions:
What do these specifc error messages mean?
Is there any way I can get more specific information on what's wrong with the .sln file?
Is there something wrong with the GUIDs I'm generating? Should I be using the Visual Studio tool to create GUIDs?
Is there some metadata or other invisible special sauce in the file that I'm missing?
I'm pretty sure the issue isn't with text encoding--I used notepad to create a UTF-8 version of the .sln and tried opening that instead.
In light of everything, it seems like my GUIDs are causing the issue--though I'm not sure how or why.
Update
The only major difference I noticed between these files was the file size. The two files differ by exactly 3 bytes, but I couldn't see anything in the file using my text editor. However, an article by Joel Spolsky got me thinking. There ain't no such thing as plain text--everything's just a representation of 1's and 0's, after all.
I opened up the two files in a hex editor, and presto, I found the 3 bytes at the start of the Microsoft-generated file! (0xEF, 0xBB, 0xBF). These three bytes also appear in a Visual Studio 2008 solution I had lying around on a different machine. I could probably write my code to slip these bytes into the file before I start writing the solution, but that still begs the question:
What the heck are these bytes for, and why is Microsoft using them?

What you are contemplating is a UTF-8 byte order mark.
It is used to indicate that the file is UTF-8 encoded, and it is supposed to be rendered as a blank, zero width space. If you have the choice, please don't use it -- it makes the file more difficult to read with standard text editors.
Opening the file with notepad and saving it as UTF-8 encoded text will add those three bytes for you. But again, don't use the BOM on files which are meant to be portably read.

Debug Visual Studio with Visual Studio:
Before opening your generated solution with Visual Studio, open another instance of Visual Studio, go to Debug->Exceptions and check all the check boxes, then go to Debug->Attach to Process... and attach to devenv.exe. Now open the solution in the other VS, and you'll get a break and a call stack which might give you more information.

To add to the answer I accepted, in the case of Qt, I made use of the following method in the QTextStream object I was using to write the solution file:
void QTextStream::setGenerateByteOrderMark ( bool generate )
Syntax is like so:
QFile fileHandle("mylib.sln");
QTextStream fileStream(&fileHandle);
// ...file open and error handling goes here...
fileStream.setGenerateByteOrderMark(true);
fileStream << "\nMicrosoft Visual Studio Solution File, Format Version 11.00\n";
//etc, etc
This will make sure that your file has the Byte Order Mark, which in this specific case, Visual Studio needs in order to open the file.

Related

trouble with setting up OpenCV 4.1.1 on Visual "Microsoft studio 2019" ? (Illegal Instruction.)

I am trying to use Open Cv on Visual studio to write c++ code. I tried a lot of ways to reach this goal for 3 days. here is what I did in these days:
**1.download and extract open cv 4.1.1 (C:\opencv).
2.download and install Visual Microsoft Studio 2019.
3.copy the bin directory of open cv to the system variable path.
(in my case:"C:\opencv\build\x64\vc15\bin;C:\opencv\build" )
4.add include folder to the project's properties(my project name is opencv):
(properties->configuration properties ->edite include directories value to : (C:\opencv\build\include )
5.edite library directory to ( C:\opencv\build\x64\vc15\lib)
6.then in linker menu->inpute->adittional dependancies -> edit its value to "opencv_world411d.lib" .**
now I write a simple code to test open cv:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat im = imread("cameraman.tiff", 0);
}
this code built correctly but when I run it It doesn't work with error :
Unhandled exception at 0x000007FEBA8D3AE2 (opencv_world411d.dll) in opencv.exe: 0xC000001D: Illegal Instruction.
gfluidimgproc_func.simd.hpp not found
You need to find gfluidimgproc_func.simd.hpp to view the source for the current call stack frame
"I added screenshot"
error report
also, I tried Cmake too.
first, configure and generate OpenCV's source file.
second, open the project in Microsoft visual studio and build all
then I build the install folder.all has been done successfully.
questions:
1.how can I fix this error to run OpenCV on Microsoft visual studio 2019 ?
does Microsoft visual studio 2019 support open cv 4.1.1? have you tried it?
tanks for your attention.
my operation system is: windows 7
intel core i5
>>4.add include folder to the project's properties(my project name is opencv): (properties->configuration properties ->edite include directories value to : (C:\opencv\build\x64 )
This is wrong, you should add C:\opencv\build\include and C:\opencv\build\include\opencv2 to the include directories in your case.
I test your case on My PC, I use VS2019 and OpenCV4.1.1 to make a test. Your other steps are correct. This step will cause the header file not to be found, so the corresponding function can not be identified and will be displayed as illegal instructions.
I have the same problem and from what I understand it is because we compile in x64 bit and execute it on an old CPU which doesn't support sse3 instructions (in my case an old i5 750). I believe your only solution is to recompile OpenCV either in 32bit or in 64bit with sse3 disabled.

C++ Port in VS: new project crashes (same files & settings)

I am trying to move the code from a preliminary project to a new project (both made under Visual Studio 2012).
The original one has been made as a console application and I want the new to be a Windows application. I created an empty project and moved the files/set the library paths.
It is a simple OpenGL program with shaders.
EDIT:
It happens that even when I switch back to creating a Console application with the same .vcproj properties, I have a fatal error on Release and Debug.
You can find them below.
Why does my program crash? All the library paths are set just fine because it's the same settings used for a previous project with the same files that DID work (in a different solution).
Errors
Release crash location (outside a #ifdef _DEBUG in the dbghook.c
file)
int _debugger_hook_dummy;
__declspec(noinline)
void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
/* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
(_Reserved);
_debugger_hook_dummy = 0;
}
Debug crash location (fread.c) - a pop-up error window appears
(Debug assertion failed):
_VALIDATE_RETURN((stream != NULL), EINVAL, 0);
After cutting my source file in parts, I managed to debug this. The problem was not the port (sorry).
I had minor issues dealing with the location of the executable: Visual Studio puts them by default in SolutionDir/DebugorRelease while I was looking for them in ProjectDir/DebugorRelease.
But the main problem came from a change of function.
There is a side file I use to load textures, which is pretty old and uses fopen to open files.
Following the warnings I got, I changed all the fopen occurrences to fopen_s, with all necessary modifications. That's the precise line where the program crashed.
I put back the fopen version, checked the file locations, and it went back to executing (not in Visual Studio but through command line only, like the original project). That's for the Console Application.
To make it a Windows Application, the following line does the job, and this time, though command-line-only, it works for real.
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

Visual Studio 2013 Express - How do I add resources?

I'm currently linking to the >dynamic< libs in SFML but I have no idea how to add resources in Visual Studio 2013 Express C++. I've quite recently started out with C++, coming from C# where adding resources is as simple as drag-n-drop.
I know there's something with .rc files and headers, but I didn't find any guide on it. What I need to do is add the dll's so I don't have to manually paste them with the .exe and I also need to add .png's. Right now I'm loading them from a folder next to the executable, I don't wanna do that.
How do I do this?
You can just add an [.rc] file to the project.
An [.rc] file is a purely textual resource script that you can edit as text, or you can use various 3rd party resource editors (you don't need that for adding image resources, just check out the RC syntax).
Visual Studio Express lacks resource editors, but does support automatic recognition of, compilation of and linking of resources.
Example
Here's an example [.rc] file, just a single line, using a free icon that I just downloaded from the net:
100 ICON "resources\\Bad-Blood-Yolks-Grin.ico"
Corresponding C++ source code, presenting the icon in a message box:
#undef UNICODE
#define UNICODE
#include <windows.h>
auto main() -> int
{
MSGBOXPARAMS params = {sizeof( params )};
params.hInstance = GetModuleHandle( nullptr );
params.lpszText = L"Click OK to dismiss this box.";
params.lpszCaption = L"Καλὴ τύχη!"; // "Good luck!" in Greek.
params.dwStyle = MB_USERICON;
params.lpszIcon = MAKEINTRESOURCE( 100 );
MessageBoxIndirect( &params );
}
Result:
All done in Visual C++ Express for Desktop 2013, or whatever it calls itself. :-)
In order to synchronize identifiers between resource script and C or C++ code it's common to include a header. The resource compiler understands the most basic C preprocessor directives.
Oh, also, I added the [.rc] file as just a text file. Visual Studio Express reacts to the renaming, "rc" file extension, by popping up a warning box that it isn't supported. Just ignore the box, and to edit the file right-click and choose text editor.

having trouble compiling old VC++ 6 c++ code

I am trying to compile MSVC 6 C++ code using MSVC 2008 Express on 64 bit windows 7. When I tried to open the .sln file, I get the error "project file dpcwebcfx.vproj could not be loaded". I don't have the .vproj file, but I do have dpcwebcfx.dsw file. So in the .sln file I changed
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dpcwebcfx", "dpcwebcfx.vcproj", "{355F3EB4-3B37-4272-B454-340E9B3BD9D3}"
to
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dpcwebcfx", "dpcwebcfx.dsw", "{355F3EB4-3B37-4272-B454-340E9B3BD9D3}"
Now I get an error converting the dsw file: Cannot load the project due to a corrupt project file. What should I do? Am I missing a file so that I can't open this project?

__REQUIRED_RPCNDR_H_VERSION__

I create a header file from an IDL . The IDL file has been compiled in Visual C++ 2005 .
The generated header file contains #define REQUIRED_RPCNDR_H_VERSION 475 .
I tried to use this header file in Visual Studio 2003 , where rpcndr.h contains
{
#define RPCNDR_H_VERSION ( 450 ) // and
#if ( RPCNDR_H_VERSION < REQUIRED_RPCNDR_H_VERSION )
#error incorrect <rpcndr.h> version. Use the header that matches with the MIDL compiler.
#endif
}
Since 450<475 , i get a compile time error . Is there any way i can use the header file in Visual Studio 2003 . Do i need to make changes in the compiltaion setting of idl file .
PS : I have to compile the idl file in Visual C++ 2005 only . ( I do not have a choice to compile it in VS 2003 ) .
If your 2003 and 2005 configurations are using the same version of the Windows SDK, you might be out of luck (and/or just need to hack it and hope it works). Usually, though, you can make them compatible if they are using the same version of the SDK utilities and headers.
I don't have any info specific to this issue, but I have had similar problems in the past which I have resolved by pointing both versions of VS to the same later SDK version.