How can I compile C programms in Visual Studio 2022 using VCPKG? - c++

I have set up VCPKG and it works fine when coding in c++ but when I try to switch to C, It stops working. It gives me an error saying that I have to select a valid starup item even though I have chosen current document as my startup item. From what I can see, when I compile c++ programs they are compiled using MinGW as well (or so it says in the top bar).
This is what how it looks in c++:
And what happens when I run it:

I notice that you set cpp as startup item. So I deduce that you did the same for the c file. Visual Studio is different from VS Code. It is recommended creating a new project for the c/cpp file and select the project as the startup project instead of a single file.

Related

Cannot associate .hpp, .cpp extensions with visual studio 2017RC in Windows 10

You know my question. Here is the longer version. Downloaded 2017RC, it took me a day to set it up to work with UCRT, CMake, Google test and all the goodies. Then I tried to associate the usual hpp, h, cpp extensions two ways:
Control panel -> Default Programs -> Set Default Programs, choose Visual Studio 2017RC and then -> Set Program Associations where all the possible extensions that can be handled by this program are listed. None of the usual C++ extensions are listed.
Right click on a .cpp file, Open with, visual studio 2017 RC doesn't show up in the apps list, hunt it down and click on it. A dialog box pops up saying that The program you have chosen cannot be associated with this file type.
FYI, currently all the c, C++ extensions are associated with Qt. Am I to think that RCs are not expected to have this feature? Or is it some other sub-program within VS, with which the association should be made? Thanks for your help
I had the same problem for Visual Studio 2015. The answer here is a good starting point:
https://superuser.com/questions/977271/windows-10-visual-studio-2015-xaml-file-association
Specifically, modifying "HKEY_CLASSES_ROOT.cpp". I changed the (Default) String value to VisualStudio.cs.14.0 and it now opens .cpp files in Visual Studio 2015.
You would have to use whatever version Microsoft has for Visual Studio 17. Take a look at an existing working file extension to see what it uses.
As usual, backup everything before messing around in the Windows registry.
For what it's worth, Microsoft appears to have fixed this bug, and will apparently be releasing the fix in the next release:
https://developercommunity.visualstudio.com/content/problem/3122/vc-file-association-not-correct.html

Missing MFC71.DLL for new empty VC++ Console Project

I am trying to get an slightly older project running again. I used the code last summer just fine. Unfortunately I did not keep the VC++ project files, just the code. As such I created a new VC++ console project and selected the "empty project" option in the process. Upon adding the code and pointing the compiler and linker to the appropriate folder I compile successfully. From there I attempt to debug and receive the message
The program can't start because MFC71.DLL is missing from your
computer. Try reinstalling the program to fix this problem.
From what I see this DLL is in the Visual Studio .NET 2003 which as far as I can tell my project should have no dependency on. I am using a robotics simulation library called callisto which I suppose could depend on it. However that project seems to be gone so I can't confirm as much from the project website. How does one go about using MS development tools to determine as much? In the event that it does not, what other possible reasons would a new project depend on such an old DLL?
Note that if you are using that library in form of DLL (already compiled code that internally depends on redists of VS 2003), you can verify this by using the Dependency Walker (it is a simple .exe file that you can download here: http://www.dependencywalker.com/ and just drag-n-drop this DLL on it).
Also note that you don't need to install whole Visual Studio. Redistributable package for VS 2003 will do.
EDIT: "The Visual C++ 2003 runtime was not available as a seperate download" ~ check Where to download Microsoft Visual c++ 2003 redistributable

How to compile and build librsync using visual Studio 2010?

We have a requirement where we need some rsync library.I came across something named as librsync and downloaded it from this Link
In the readme file of this library its mentioned
The PCbuild directory contains a project and pre-generated config
files for use with the MSVC++ IDE. This should be enough to compile
rdiff.exe without requiring cygwin.
But when I opened it in MSVC++ IDE and built it,it gave me more than 36 compile time errors.I guess I'm doing something wrong or missing some important steps to do it.
I am using MS Visual Studio 2010 premium on windows 7 PC.
Please help in case anyone here has successfully ran this project library using visual studio 2010.
After opening the .dsw VC++ 6 workspace file with VS2010 and using the automatic project conversion, I had to make the following minimal changes to get it to compile:
Added #define inline __inline to the bottom of PCbuild\config.h. VS2010 doesn't support the inline keyword for C, but does have __inline.
Added HAVE_CONFIG_H to rdiff Project Properties, C/C++, Preprocessor, Preprocessor Definitions. Otherwise, the project wasn't using the pre-built PCbuild\config.h in some cases. Right-click the rdiff project, select Properties and make the changes in the dialog below:
Added rollsum.c to the rdiff Source Files list. Not sure why this got dropped from the conversion, but it was needed to compile.
There were still 72 warnings, and I didn't test the result, but that should help you get started.

Compile single C++ file in Visual Studio 2010

I want to compile a single file in c++ using Visual Studio 2010. I created a new file, not a project, and wrote some "hello world" code and I want to compile it and run it. How to do so?
I've searched here and in Google, I got things like F7 or F5 nothing worked.
You can follow this guide from MSDN to compile standalone C++ files without an IDE.
In Visual Studio 6.0, you could load up a single CPP file, with a main(), and compile it. Can't remember if this was taken away in Visual Studio 2008 or 2010, but it's gone.
It used to be easy to fire up a new instance, paste in some test code an just run it. Now it takes creating or using a dummy project, as others above have noted.
Not hard, just less handy than before.
Probably for simple tests editing your source file in some editor like Notepad or Metapad and building from the command line with something like:
cl /EHsc /W4 /nologo YourSource.cpp
would be just fine (faster than starting up VS2010 IDE, create new project, etc.)

use msbuild to compile a vcxproj created by vs2010 on a computer without vs

I have created a large Visual C++ 10.0 project which builds nicely within the visual studio ide as well as within the "special" Visual Studio Command Prompt using msbuild with a vcxproj file.
However this project needs to be compiled by computers that do not have the vs ide, but only have the msbuild tool and the vc++ 10.0 runtime files.
The problem is that the vcxproj (created by the vs ide) file contains references to files such as Microsoft.Cpp.Default.props and Microsoft.Cpp.targets which clearly won't be available in a computer without visual studio.
Since all the compile and link command line options are available and fixed (no changes will be necessary), how is it possible to create a new vcxproj file to implement the compiling and linking of the project using these options?
I was finally able to make some tests on a "clean" computer. These are the results:
First, I installed .NET Framework 4.0 from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17718. Along with it, MSBuild 4.0 was also installed automatically. When I tried to compile I got the following error:
error MSB4019: The imported project "H:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
which means that extra files are needed to compile the vcxproj and these files were missing. Note that simple project files written by hand (and not by the VS IDE) are expected to compile without problems since they contain no references to theses files (I did not test it for certain).
Next, I installed Windows SDK 7.1 from http://www.microsoft.com/download/en/details.aspx?id=8442. The error about missing files disappeared, but I got a new one. This new error (along with the way I overcomed it) is described in http://www.damirscorner.com/CommentView,guid,9121bd6b-876c-4051-8487-de1b95a7e919.aspx.
Doing the above successfully allowed me build my vcxproj file on a computer without vs2010.
I think that the files that you mention are not part of Visual Studio. They are part of MSbuild.