r/cpp • u/GodRishUniverse • 4d ago
Why is there no proper build system (CMake exists but...yk) like cargo in C++?
Meson and Bazel exist but I have not seen widespread adoptability.
Edit: I forgot to add package manager in title as well lmao
0
Upvotes
14
u/jesseschalken 4d ago
There's a bazillion build systems for C++. People are not running
g++directly as part of their workflow.Are you talking about a package manager?
16
u/ezoe 4d ago
C++ wasn't and still isn't owned or developed by single organization.
After Bjarne Stroustrup implemented the original C with Classes and C++, many companies tried to write their own C++ compilers.
Bjarne Stroustrup didn't started an organization to centralize the evolution of C++ but he instead chose ISO standard.
During late 1980s to 1990s, there were so many environments and the nature of C++, C compatibility, zero overhead and compiled to native code, made creating these common build system with package manager difficult.
Even after 2000s, C++ still retain the old way and there is no strong central authority to develop the common package manager for C++.
5
u/johannes1234 4d ago
Since different people have different opinions and C++ has a few decades of history during which the environment (from DOS machines with floppy disks to today's machines) changed and during which people created their systems and moved them along, based on their needs.
Also one decided that the standard focusses on the language and leaves the way compilers work and at invoked out and has a world where multiple compilers exist.
4
u/official_business 3d ago
any project of any complexity will have its own build system and no one is going to rewrite that because the committee pulled something out of its ass.
My company would ignore any such project completely.
7
u/TheRavagerSw 4d ago
Look, this is a very complicated problem.
Build systems operate on higher level compared to your toolchain, which is a fancy word for a collection of tools such as your compiler/linker/sdk. Your build system uses these tools to produce binaries. Package managers operate in a higher level then this, they call these build systems in a specific order and store their output to some location in your disk.
The way you would ideally build your software is that, you have sources in your disk, you write package recipes for them, you call your package manager, it calls build systems and builds the thing you want.
The real complexity occurs at the fundementals, such as when you need to build a program to build or use a library(icu, qt) or it relies on different languages. Such as some old math libraries using fortran.
Rust's cargo isn't a good solution, because it relies on a global registry, meaning you download sources from the internet when you build stuff. Additionally, if you want to use languages other than rust, it fails to deliver. Rust is only really useful in professional settings if you use bazel.
So, this is a very hard problem without easy solutions, employers should pay competent devs their due to get it solved. Rust isn't a solution and never will be.
3
u/lordnacho666 4d ago
History. There's just a lot of things that build up with an old language like cpp, and with no original build system various people have tried to do their own.
4
u/Aerocatia 4d ago
I think CMake with the Common Package Specification is really really good and I wish vcpkg would use it. It solves a lot of the problems seen with C++ packaging and does not introduce some flaws seen with Rust's cargo.
2
u/nderflow 4d ago
Because C and C++ were in widespread use before Internet access was widespread.
As far as I know the kind of package/dependency management you're thinking of was not well known before the invention of the Perl CPAN system.
2
u/ventZl 4d ago
Given the extremely wide variety of ecosystems where C and C++ are used, it is naive expect that any build system that will cover them all won't get as complex as CMake, or leave a lot of stuff at the user (as Makefiles and/or Cargo).
2
u/Abject-Kitchen3198 4d ago
What's wrong with make?
2
u/CreativeAlbatross319 4d ago
Same reason as Go, Zig or Rust not widely adopted in the industry, except hobby projects and few leading projects from big corps.
There is a term for this: path dependence
1
u/13steinj 2d ago
C++ does not have a reference implementation, only a standard specification.
Historically, people would just share source tarballs, sometimes static archives. In practice, the latter works often enough to have been acceptable from more or less the start of C up until 2011. After that, with the required ABI break in C++, even though itself irrelevant, I have seen an exponential uptick in poorly formed static archives. Usually because they shove in another common dependency without versioning/mangling the symbols.
CMake isn't perfect, but it gets the job done and is flexible and powerful enough for everyone's needs. Where it isn't, it's open source-- submit a PR. Package management for a number of languages attempted to get standardized over 2016-2020, there was a widespread crisis in getting a package manager for multiple languages. But with no reference nor majority implementation for C++, neither did a single one come about. Nowadays there are 3 (4?) major competing systems: Conan, VCPkg, Bazel, and CPM (/honestly just raw vmake FetchContent). All that said, the public registries are all subpar. Convincing a project to have a high quality canonical recipe, let alone 3+, is a high bar.
There was work to standardize a spec with the Ecosystem IS and also with the Common Package Specification. The former died after the committee made it clear they didn't care, the latter is too early to tell if it will be useful. The Ecosystem IS, IMO naively, rejected creating or blessing an existing package manager as an "official" one.
1
u/UndefinedDefined 4d ago
In the long run all the "history" arguments are irrelevant.
Starting a go or rust project is super simple and building programs using these languages too. Try to build servo browser and compare that to building chromium.
I think that this entry barrier is doing no good to C++ honestly.
1
u/Slsyyy 4d ago
History. C/C++ build system was designed in an evolutionary fashion starting from simple header/source files and shared/static libs. This blurs responsibility of each part (compiler, build tools, package manager, modules) and each of them suck, because they don't work together and try to be as independent as possible
The correct way from a modern perspective is to have everything developed together with a single goal of building the end result artifact
0
u/mark_99 4d ago
I'd recommend using pixi for toolchain, cmake+ninja for build and either Conan or vcpkg for package management.
-1
u/n1ghtyunso 4d ago
the problem is not that there isn't one, its that there isnt (just) one
-12
u/zuzmuz 4d ago
cause it's a poorly designed language with a horribly fragmented ecosystem.
5
u/[deleted] 4d ago
[removed] β view removed comment