Home > Back-end >  What to do in the absence of a .sln file?
What to do in the absence of a .sln file?

Time:12-28

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?

CodePudding user response:

There are numerous build systems in the world, but for the Windows ecosystem there are a few dominate ones.

  1. 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#).

  2. 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.

  3. MinGW (Minimalist GNU for Windows) has its own 'makefile' build system.

  4. 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.

CodePudding user response:

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