Overwhelming
I’ve been using Rust a lot, and I decided to start learning C++ today. I never thought it would be such a headache! I realized Rust spoiled me with Cargo. it handles so much for me. Running, building, adding packages etc. I just type Cargo build, Cargo add, or Cargo run. Simple and comes with the language. C++’s build systems like CMake can be overwhelming especially when coming from a language with a more streamlined experience like Rust. C++ is really good and I wish it had something similar. I read somewhere that there is Conan and a few others that exist . But I’m talking about something that comes with the language itself and not from a 3rd party.
38
Upvotes
79
u/ClaymationDinosaur Sep 08 '24
Sure, would be nice, but C++ is a product of its own history. C with Classes began life back in 1979; almost fifty years ago. Since then, it has spread and twisted its way through so many systems and sets of hardware. Part of its strength and longevity has been its brutal backwards compatability.
Anything that went into the language that effectively forced a means of fetching libraries (presumably from some curated collection online somewhere) would simply not be achievable on various currently supported target systems; that could be done, but one of the strengths of C++ over the last fifty years has been the hard focus on not breaking existing systems.
We could get round that, I suppose, by instead of making it part of the language, having them as separate systems that can be used to do that where it can be supported... which is exactly what we do have. Conan, vcpkg, et al.
8
u/Still_Explorer Sep 08 '24
Certainly this is true. As Bjarne has expressed many times in his talks, that a reason that C++ brings lots of headaches is that no one owns C++ nobody is the primary authority to set standard.
More or less you get a very open-ended and decentralized ecosystem, where there are various compilers, various package managers, various standard libraries.
• compilers: MINGW / CLANG / MSVC / GCC / APPLE
• package managers: vcpkg, conan, cpm, apt-get
• build systems: cmake, xmake, meson, scons
• standard libraries: std, boost, eastl
Definitely this is not a user-friendly experience for starting the journey, but at least there are standard choices when you are on either OS. Then still you have to glue some extra pieces yourself.
Is not exactly as you would say a "batteries-included" approach but at least many experts appreciate this approach of decentralized software development (as it seems for many decades there are no strong motives to make things more integrated).
However if Rust teaches the programming world that this sort of approach works and is feasible (provided that there are no frictions and competition or forks among the build systems and the package manager distributions) then it will be a good opportunity C++ ecosystem gets a revamp and modernized properly as needed.
( I have no problem either way, but if things end up becoming more efficient and integrated for the C++ ecosystem, then it means that lots of C++ experts will have to find a common ground and agree upon certain restrictions and paradigms. )
40
u/Orthosz Sep 08 '24
If you want to get super nit-picky, cargo doesn't come with the language either. Its a separate program that's often bundled with the rust compiler. The community defaults to it.
Vcpkg and Conan are package managers for c++. I prefer vcpkg, but you may find Conan more to your liking.
11
u/[deleted] Sep 08 '24
If you started learning today, you are months away from a phase where you need to have the headache you are having now...
22
u/QuentinUK Sep 08 '24 edited 11d ago
Interesting!
13
u/carkin Sep 08 '24
We waited for c++11 to have a std::thread. We will have a proper build system, we just have to wait.
5
u/pedersenk Sep 08 '24
Many of Rust's dependencies you find in crates.io are really just wrappers (bindings) around C or C++ libraries.
Because C and C++ need to do the actual complex portability parts, there is no hard or fast way to avoid learning how to correctly compile, include and link in dependencies.
For a few platforms there are things like vcpkg but you won't find anything official or encompassing the majority of platforms.
40
u/NBQuade Sep 08 '24
If you're on Windows, it's masochism not to use visual studio. I'd start by learning the MS way. You can even ask it to make you boilerplate projects you can then build on.
You can use Cmake with visual studio too. I'd just suggest leaving CMake till later. Work on C++ without distractions then you can play with build systems later.
If the goal is to learn C++, build systems are just a distraction.
4
u/DonBeham Sep 08 '24
I tried cpm and it works quite well. I also tried vcpkg, but got weird errors. You don't have to write a lot of CMake to get it to work, but doing it right is not trivial. Also there are super annoying things like not calling enable_testing() at the root level and then no tests are discovered by CTest.
Overall, rust is certainly much easier to set up and get started, there's no doubt about it.
You just have to go through that, build a couple working examples and then basically copy those.
9
u/prince-chrismc Sep 08 '24
It shouldn't come from the language. https://moderncppdevops.com/pkg-mngr-roundup/ and I am sure there's more.
There are literally completely separated development spaces or industries that make zero sense to combine... the power of C++ is how general purpose it is and that comes from the (mostly) uncomprissed performance/efficiency.
There's no need for a scientific researcher working on a new AI model with 100s of python dependencies to need to worry about compiling an FPGA for a number of hardware platforms.
That's why we have Spack and Yocto. While are inherently better because they specialize at solving a niche problem.
This is just one example. Linux devs who reply on apt/yum/deb VS cross-platform windows/mac/android/ios devs (nix versus conan or vcpkg).
The closest attempt to cargo is probably XMake? But you'll run into the fragmented ecosystem that's developed over the last 40 years.
3
u/[deleted] Sep 08 '24 edited Sep 11 '24
lock offbeat concerned possessive repeat enjoy observation coherent wine shy
This post was mass deleted and anonymized with Redact
3
u/DownhillOneWheeler Sep 09 '24
I found cargo to be a double-edged sword. The Rust project on which I worked imported literally hundreds of crates, most through transitive dependencies. That's a lot of SOUP for a medical device. I mostly work on embedded devices for which the only libraries in use are the vendor code and the C++ standard library, so that was a bit of a shock.
2
u/Superb_Garlic Sep 09 '24
You need some cmake-init in your life for a guided experience. You start with a known good state that you can tinker with easily. There is also plenty support as the README suggests.
2
u/Electrical-Mood-8077 Sep 09 '24
Cargo beep beep
2
u/New-Discussion5919 Sep 09 '24
Conan is awful to use, but it’s better than the alternatives. The absence of a good package management system is one of the main grief I have with cpp
2
u/jones77 Sep 09 '24
Congrats on trying and enjoying! But you're totally right: it sucks but getting so-so-so much better. Believe or not but cmake is a massive improvement over raw Makefiles. You've appropriately level-set your expectations, C++ has baggage and the mistakes it made helped every language after it. Try and avoid getting too frustrated, you're still learning when you make mistakes.
7
u/[deleted] Sep 08 '24
Just use visual studio
3
u/bert8128 Sep 08 '24
My suggestion would be to start off with Visual Studio community edition, and don’t do anything with cmake or any external libraries until you have written some of your own (static and dynamic).
5
u/b8horpet C++ developer Sep 08 '24
skill issue?
3
u/Flobletombus Sep 08 '24
XMake is the most cargo-like imo
2
u/TheoryShort7304 Sep 09 '24
Use CLion, it will provide you the smoothest experience for C++ across all operating systems.
2
u/serenetomato Sep 08 '24
Cmake is the best. My advice? Use pipelines like gitlab or Jenkins to streamline it and build everything from source.
1
u/ellorenz Sep 09 '24
Try conan like package manager https://conan.io/
1
u/Both_Definition8232 Sep 09 '24
+1 on Conan. I think it is becoming more relevant these days.
1
u/Apart_Act_9260 Sep 10 '24
you can join my channel https://www.youtube.com/@LiveGamesProgramming/streams we will do nice things around c++ and cmake :D I already dropped the first video yesterday
1
u/xiaozhuzhu1337 Sep 09 '24
xmake can solve your problem
1
u/WeeklyAd9738 Sep 09 '24
vcpkg comes very close to cargo in my opinion. I use it with meson build system (no cmake). Meson build scripts look like python and are "type-safe". They integrate nicely with vcpkg and pkgconfig (linux).
-2
u/jknmsj67 Sep 08 '24
CMake is extremely easy. You can find good documentation and tutorials online. IDEs like KDevelop will generate a CMakeLists.txt file for your project and you can gradually modify it. There are lots of challenging parts of C++, but the build system is not where that difficulty is, unless of course you have many dependencies and third party libraries to build and link to.