What to do in the absence of a .sln file? - c++

I'm just starting in the world of C++. I was kind of forced into this because I want to study a Physics simulation. With a lot of effort, I found out that I needed to install Microsoft Visual Studio on my computer in order to edit and compile the source files that are available on GitHub.
However I noticed that some of the authors on GitHub do not include .sln files in their projects, and then I'm unable to open/edit/compile them with Microsoft Visual Studio. Conversely, those projects containing an .sln file and that are meant to run on DirectX are the ones that I was able to compile/execute after making my own modifications.
So... What is lacking in those projects that do not contain an .sln file or that are not meant for DirectX?

There are numerous build systems in the world, but for the Windows ecosystem there are a few dominate ones.
MSBuild (Microsoft Build) is the default build system for Visual Studio. .vcxproj files are the Visual C++ project files that use MSBuild, and the .sln files are meta-files that organize one or more .vcxproj files (or .csproj files for C#).
NMake (Microsoft Program Maintenance Utility) is the older 'makefile' build system from Microsoft. It's still around, but has not been updated in many years. Visual Studio can also support nmake-based .sln/.vcxproj files, but this has fallen out of favor over time and is all-in-all fairly clunky.
MinGW (Minimalist GNU for Windows) has its own 'makefile' build system.
CMake is a cross-platform 'meta-make' solution that is used by many platforms including Windows. It can target MSBuild, Ninja, MinGW Makefiles, etc. and a number of other build-systems which is why it's a popular open source and multi-platform solution. Visual Studio and Visual Code both support building with this build system, and you can of course use it from the command-line directly if you want. The presence of a CMakeList.txt file indicates this.
To provide some of the functionality of a '.sln' file for CMake, CMake 3.20 or later supports a CMakePresets.json file which makes it much easier to use within the Visual Studio and Visual Code IDEs.
See Microsoft Docs for more in Visual Studio build. For more on CMake with Visual Studio, see this article.
For general background on 'makefiles', see Wikipedia.
My list above is far from complete as there are numerous build systems out there (SharpMake, Meson, FASTbuild, etc.). For a good overview, see this blog post.

Microsoft uses .sln files as a way for Visual Studio to manage projects (files, compilation rules, dependencies, etc.), so it is Microsoft-specific.
Most of C++ projects are not written using Visual Studio however, but use other editors & build systems. Projects that do not have a .sln file, could have CMakeLists.txt files that can be compiled with CMake (which Visual Studio got support for in recent version), or meson.build files to be compiled with meson, Makefile for make, you get the point.
There are a lot of build systems & IDEs for C++ because it existed for very long time, and because it is a very popular language (for a good reason) so people created tools that suit their workflow. However, there should not be any differences in code you write (given it conforms to a standard version of C++) regardless of the build system or IDE you choose to use.

Related

CMake generator in Visual Studio Code Windows 10 [duplicate]

I read the documentation.
It says:
A CMake Generator is responsible for writing the input files for a native build system.
What exactly does that mean?
If I have a set of C++ files in my project, are these the input files?
If I'm using Linux, what is my native build system by default? Make?
Why do the input files have to be written by the generator if they already exist?
What's a generator?
To understand what a generator is, we need to first look at what is a build system. CMake doesn't compile or link any source files. It used a generator to create configuration files for a build system. The build system uses those files to compile and link source code files.
So what's a build system?
A build system is a broad term that groups together a set of tools used to generally compile and link source code, but it can also include auxiliary tools used during a build process.
For example, in a multi-stage build system, one executable might be built to be used in the build process of another build.
Depending on the tool chain used on a system, CMake will generate multiple files and folders to allow the building of the source files referenced in the CMakeLists.txt and supporting .cmake files.
Sometimes multiple build systems may be installed on a computer, like for Windows you could have a Visual Studio and MinGW build system. CMake allows you to specify which if these build systems to generate configuration files for.
CMake includes a number of Command-Line, IDE, and Extra generators.
Command-Line Build Tool Generators
These generators are for command-line build tools, like Make and Ninja. The chosen tool chain must be configured prior to generating the build system with CMake.
The following are supported(**):
Makefile Generators
Borland Makefiles
MSYS Makefiles
MinGW Makefiles
NMake Makefiles
NMake Makefiles JOM
Unix Makefiles
Watcom WMake
Ninja Generators
Ninja
Ninja Multi-Config
IDE Build Tool Generators
These generators are for Integrated Development Environments that include their own compiler. Examples are Visual Studio and Xcode which include a compiler natively.
The following are supported(**):
Visual Studio 6
Visual Studio 7
Visual Studio 7 .NET 2003
Visual Studio 8 2005
Visual Studio 9 2008
Visual Studio 10 2010
Visual Studio 11 2012
Visual Studio 12 2013
Visual Studio 14 2015
Visual Studio 15 2017
Visual Studio 16 2019
Visual Studio 17 2022
Green Hills MULTI
Xcode
Extra Generators
These are generators that create a configuration to work with an alternative IDE tool and must be included with either an IDE or Command-Line generator.
The following are supported(**):
CodeBlocks
CodeLite
Eclipse CDT4
KDevelop3 (Unsupported after v3.10.3)
Kate
Sublime Text 2
If I have a set of C++ files in my project, are these the input files?
Yes, they are some of the input files. For a make build system you also have a MakeFile. For Visual Studio you have a solution file (.sln). With both systems there are additional files needed that CMake knows how to create given a proper CMakeLists.txt file.
If I'm using Linux, what is my native build system by default? Make?
Generally, yes, but other build systems could be setup like Ninja.
Why do the input files have to be written by the generator if they already exist?
Some source files may already exist, but CMake has the ability to generate header and source files. Also as mentioned above, there are configuration files that must be generated that depend on the source files supplied in the CMakeLists.txt file.
** According to the documentation for CMake Version 3.9 & 3.15 & 3.25
Maybe a picture is worth a thousand words.
A CMake Generator is responsible for writing the input files for a
native build system.
means that CMake prepares build scripts for a native build system when no generator is specified. In Linux the default build system is Make and its input file are makefiles, which are then interpreted and a build is executed accordingly. Before the first execution of CMake build scripts do not exist.
C++ source files (or any other source files) are not input files to a build system. Build system scripts specify how to handle source file in order to produce binary executables.
As far as I know, the standard native build system in Unix is GNU Make (gmake) known as "make".
The Google guys/gals also released a different tool called Ninja.

Installing a library in Visual Studio 2019 C++

I am trying to install this library in Visual Studio 2019
https://github.com/alex-87/HyperGraphLib
The instructions only show how to do so for linux/unix I was curious how I would do this for windows. I can download the .zip but where would I extract this and how do I get Visual Studio to install the library.
Visual Studio can directly open a CMake project (CMakelists.txt indicates that).
That said, very often projects are in theory "cross platform" but in practise they don't work in Windows because no one has bothered to test them there (mostly because an alternative would already exist or the actual developers do not care much). Projects that have better chances to work with Windows usually come also with a .vcxproj/.sln.
click on project, properties, link editors , input and add the dependencies (with keyboards only )

Generating CMakeLists.txt from Visual Studio

I have used several C++ libraries that ship with CMakeLists.txt for building them on various platforms. It works well in most cases. My primary development environment is Windows. However on Windows using Visual Studio, I want to build cross-platform C++ libraries that I can then package and ship for multiple platforms. Is there anyway (some tool etc.) using which I can generate CMake configuration file (CMakeList.txt) for my Visual Studio C++ Library project?
vcproj2cmake seems to be the answer: http://sourceforge.net/projects/vcproj2cmake/

How to downgrade solution from Visual Studio 2010 to Visual Studio 2005?

I have a huge Visual Studio 2010 solution. I work with Visual Studio 2005, so I want to convert the solution to the desired version. Basically, it's a portable C++ code so it should compile on Visual Studio 2005 too. Changing the version in the *.sln file doesn't help because the *.vcxproj format is completely different from the old *.vcproj format.
Recreating the solution by hand is not an option because of its size. Also there may be some non-default compiler flags, dependencies, etc. that I don't know of (and I can't look through ALL this XML junk that I don't understand).
There is already a related question on How Do I Downgrade a C++ Visual Studio 2008 Project to 2005. However, the utility suggested there supports at most Visual Studio 2008.
Any suggestions?
It really totally sucks, that every proprietary IDE today thinks it needs to create its own project file format.
"Dear IDE developers, just use Makefiles and create a nice GUI for it so that also people without Makefile knowledge can use it!" In VS6 it was at least possible to import/export Makefiles, but not today anymore. And it was possible to use nmake for automated builds. No IDE needed to be installed, just the toolchain which could be grabbed by a simple checkout without installation.
I use CMake now. It's free, it's cross-platform, it is well supported in free IDEs like KDevelop, QtCreator, etc. It can generate Makefiles and Visual Studio projects.
So you maintain only one project source, the CMakeLists.txt file and can work with any IDE. No pain with different versions of Visual Studio or with other proprietary project file formats.
This way you can generate or VS projects for developing and you can generate Makefiles for commandline builds using nmake like in the good old days.
BTW, it's much easier to change settings in a CMakeLists.txt than clicking through various GUI dialogs. But this is a matter of personal preferences.
In my work made a utility which utilized the EnvDTE.dll and scanned a vcproj-file and optionally all vcproj-files within a sln-file. It compared all settings with a "template" and would issue a warning or optionally update the setting to correct values. We used this utility so that settings would be verified to be correct and consistent throughout all projects. I haven't updated the utility to 2010 yet due to other priorities.
EnvDTE hasn't changed much from Visual Studio 2008 to Visual Studio 2010. Perhaps it is possible to create a simple utility which opens the vcxproj-file using DTE100 and saves it using DTE90, or earlier.
Easiest way is probably to create a new project in VS 2005, and use the add existing item dialog to add the code to the project. I'd suggest using 'Empty Project' as the project type, so you don't have a lot of rubbish autogenerated for you that you'll just delete anyway.
I haven't tried it, but this looks promising:
http://www.emmet-gray.com/Articles/ProjectConverter.htm
edit: Nope, not promising, sorry :-(

Simultaneus development in Visual Studio and a Linux IDE

I am trying to get started with an existing open source project (QuantLib) using Linux operating system. However it seems that most developers use Visual Studio (judging from the project files committed with the source).
Which Linux C++ IDE would be most compatible with VS project files? Is there a way to import/export them, so that I don't have to create my own projects from scratch (and update them every time someone adds a new file)?
EDIT: Its all unmanaged code
In my experience, the best method for doing dual-development on Linux & Windows is to throw away the existing Visual Studio project files and, instead, use CMake to generate the platform-specific build environment. It's capable of outputting Nmake makefiles (for command-line Windows builds), Visual Studio projects, and Linux makefiles. The documentation leaves a bit to be desired but once you have it up and running, it's very easy to maintain.
The FAQ provides installation instructions for MinGW. It seems that there is a GNU Makefile included, so you don't need to mess with Visual Studio project files.
Aparantly they they only build on MAC and Windows.
Instructions here: http://quantlib.org/install/macosx.shtml
But since MAC is basically BSD Unix it should be identical (or with little trouble) to get it up and running on Linux.
The following should work (though you may need to look at the configure options)
1) Install Boost.
2) ./configure
3) make
You'll definitely want to check out Mono, it might be just what you're looking for: http://monodevelop.com/