Visual Studio 2010 compiling .cpp files as .c files - c++

I'm working one a Visual Studio solution which was generated using CMake (not sure if this is relevant).
In this solution there a c file, I wanted to change it into a cpp file, so I renamed it and changed the extension.
However, Visual Studio still treats it like a c file and gives compiler errors whenever I add any c++ style code.
I'm stuck, any advice would be much appreciated.

Project Properties, Configuration, C/C++, Advanced, change "Compile As".

Related

Is there a way to build a project with multiple C++ files efficiently in Visual Studio Code?

I have a project in Visual Studio code with > 10 .cpp files. The reason they're split up this way was to make compilation faster, and it is faster in Visual Studio 2022. However, when using a build task in Visual Studio Code that simply includes all .cpp files it can find, it obviously compiles really slowly, as expected. But, is there a way it can compile individual .cpp files into object files, and link them at the end, only recompiling each .cpp file if it's contents have changed?
Also, I'm running Windows.
Solution: Use CMake. It's less complicated and more reliable than Visual Studio build tasks. Comments on my original question clear up how that's done.

Is there a way to change the Visual Studio file extensions for modules?

I would like to prefer to name module files .cpp since I am on my way to start a new project and I try to use modules only.
For this reason I think that my implementation should go into .cpp files rather then .ixx files.
I develop the project in C++20.
Is there a way to change the modules file extension to something else other than .ixx in Visual Studio 2022?
By the way: what is the reason for Visual Studio to only allow the .ixx extension for modules? Why not let the developer pick their preferred extension?
Default logic in Visual Studio is tuned to treat files based on extension. So .ixx is assumed to be a module interface (i guess i in the extension stands for interface) and .cpp is assumed to be a file for translation unit. However this behavior can be altered from file properties:
In order to use a different file extension with MSVC so you can use intellisense in Visual Studio Code, there is actually a work-around.
With the cl.exe command, there is an '/interface' option. You can do like so:
In My cl.exe CommandFile:
/interface /Tp UI/ApplicationHost.cpp
/reference ApplicationHost=Build\Debug\ApplicationHost.ifc
UI/WorldEngine.cpp
/link /SUBSYSTEM:WINDOWS
Build/Debug/pch.obj
/Interface - Let's the compiler know there is an ifc module/header coming up.
/Tp - Forces the compiler to recognize it as a C++ file, useful if renaming to .cppm.
/reference - Tells the compiler where to get the dependency information for the following

Can't add my own .h file to standard libraries VS 2017

I'm trying to use VS 2017 and add my own .h file to standard libraries so I can include it normally in whatever C++ project (I used to copy the .h file to Program Files\Microsoft Visual Studio 14.0\VC\include and just put it there).
It worked with VS 2013/2015 but 2017 is not detecting it after putting it there.
I know this is a bad practice but I just want to know why it's not detecting it and how to make it do so.
Thanks in advance.

Visual studio include visibility

I got issue with includes in visual studio. I want to compile the project both for windows and linux.
In visual studio, I got a tiny class in .hpp file, which uses std::exception and std::is_pod<T> but I did not include type_traits nor stdexcept!! And the file compiles just fine with Visual Studio! Why?
Doing so on linux gives me error
In file included from Packet.hpp:3:0,
from AbstractPacketFactory.hpp:2,
from AuthenticationPacketFactory.hpp:2,
from AuthenticationPacketFactory.cpp:1:
ByteSerializer.hpp: In member function ‘byte_serializer& byte_serializer::operator>>(T&)’:
linux g++ is correct - why does visual studio not warn me? Is there something I can do about it? I am using VS as my primary IDE and I would like to avoid such surprise in future (currently there are 50 errors like that...)
I got a function where i made a mistake:
static_assert(std::is_pod<T>, "T must be a POD");
You have to use it with ::value or () - yet visual studio compiles std::is_pod<T> it without any warning. And that was the reason of error avalanche...
Your Visual Studio Projects might be configured to use Precompiled Headers to use. stdafx.h is there when you use Precompiled Header.
Just remove stdafx.h from Precompiled Headers and see if Compilation succeeds on windows.
You can find Precompiled Headers in Project Properties > C++ > Precompiled Header.
If you want to make cross platform projects you should remove that Precompiled setting.

Can I compile a Visual C++ project on Linux using xbuild?

I have an existing project that I compile on both Windows using Visual C++ 2008, and Debian Linux. This project uses a standard Visual C++ .vcproj file, and some .cpp and .h files. It does not rely on any Windows specific stuff. Just plain C++.
It compiles and run well on Linux, using a home made tool that reads the .vcproj file to generate a Makefile which is used with make to compile and link all files using g++.
The trouble is that with Visual C++ 2010 (and 2012), the format of the project files have changed. Even the name has been changed from .vcproj to .vcxproj. My home made tool cannot read this new project file to generate the Makefile.
Instead of upgrading the home made tool to support new project files, I was wondering if xbuild would be able to compile my Linux executable?
I tried first to compile my own (VC++2008) project, but xbuild complains that my project is a VS2003 project, which is not supported by xbuild. However when googling on this matter, I find that xbuild is supposed to support VS2005 project files. There are also some references to mdtool to support these old project files, but I seems to be integrated into xbuild now.
Furthermore, I tried to compile a Visual C++ 2010 example (HuoChess) got from the MSDN site. The result is
/Microsoft.Cpp.Default.props: Project file could not be imported, it was being
imported by [...] /HuoChessConsole/HuoChessConsole.vcxproj: Imported project:
"//Microsoft.Cpp.Default.props" does not exist.`
Now, this looks like the project file wants some Microsoft definitions of rules for the Cpp compiler. Should I fake these definitions to use gcc instead? How can I do this?
Is what I want to do ever possible with xbuild?
There is a project GCCBuild which you can use to build vcxproj projects in Linux. It simply uses same vcxproj but uses GCC to compile and build. There are multiple examples there too.
PS. I am the author of that project.