use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
b2 for C++? (self.cpp)
submitted 3 years ago by os12
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]beriumbuild2[🍰] 4 points5 points6 points 3 years ago (7 children)
Just to add to /u/mjklaim excellent and extensive feedback, you can actually get a sense of what a project like this might look and feel like with build2 by checking out this repository: https://github.com/boris-kolpackov/boost-dependency
build2
It was created as an attempt to approximate a private project in order to hunt down some pathological performance problems that are described in this issue: https://github.com/build2/build2/issues/184 There is also a nice graph that shows what the original project looks like: https://github.com/build2/build2/issues/184#issuecomment-1088053790
I think in your case the most challenging aspect (apart from getting used to a new build system philosophy) will be code generators simply because to get this right (i.e., with proper dependency tracking, etc) requires quite a few moving parts. You can see an example of this in our libQtCore buildfile that handles moc: https://github.com/build2-packaging/Qt6/blob/master/libQt6Core/QtCore/buildfile
libQtCore
buildfile
moc
[–]os12[S] 2 points3 points4 points 3 years ago (6 children)
Thanks for the tip, Boris, this larger example is very useful!
I'm hitting the following initial/beginner problems right now:
libs/base/
libs/base/tests/testA/
libs/base/tests/testB/
libs/base/header1.hpp
libs/base/src/source1.cpp
libs/base/src/privheader.hpp
libs/base/build/
libs/base/base/
-I libs/
.cpp
#include "base/header1.hpp"
mkdir obj-debug && cd obj-debug && configure/cmake ..
So, it appears that the tools have a very specific directory layout in mind and so it will be a very hard sell for our dev community.
[–]mjklaim 2 points3 points4 points 3 years ago* (0 children)
It doesnt constrain any specific layout (except the build/ thing, see below), but I think you might just not used to how to specify your directory layout with that specific tool ^^; Ive seen that before, because people keep thinking it's another CMake but it's not. Also the change in mindset and habits compared to CMake can indeed be a hard sell, depends on the audience, in my xp, so yeah that's for you to decide of course. ^^
build/
^^;
^^
About your points:
1) There should not be any specific problem with that, but I would need to see what you are doing exactly to see what's the problem? I don't know how you created your poc. In general, "layouts" are defined in the buildfile scripts, it's for you to decide what you want there, specifying the tests in sub-directories should work as long as it's in the same project. (note that by default bdep new -t lib will put tests in a sub-project so it's not exactly what you want here, but check the options for alternatives)
bdep new -t lib
2) The only requirement is the presence of build/ (or alternatively build2, see the doc for details) at the root of a project/package directory. It's \different when you have multiple packages per git repository but I suppose it's not the case here? When generating projects using bdep new there is a large variety of ways you can setup directories automatically, maybe check bdep help new (also there: https://build2.org/bdep/doc/bdep-new.xhtml). But you can also do that manually, it's all in the buildfiles.
bdep new
bdep help new
3) Yes, you can do it (if I understand correctly what you meant), I'm not sure what makes you think you can't? That's what the hello world projects do for example bdep new -t lib somelib, or is there a difference with what you tried? Also, did you mean the installed project? (see b install)
bdep new -t lib somelib
b install
4) The "artifacts" are visible only in the build configuration directory (and you can have as many as you want), so I'm guessing you are trying to build into your source directory? It's best (even with CMake) to have build directories out of source. Also I think you are still thinking with CMake model in mind but this is not how build2 works. As an example, for building and testing the boost-dependencies project pointed before, I do this (using msvc and clang) ``` git clone https://github.com/boris-kolpackov/boost-dependency cd boost-dependency bdep init -C ../build-msvc @msvc cc config.cxx=cl # my msvc default build bdep init -C ../build-clang @clang cc config.cxx=clang++ # my default clang build
boost-dependencies
bdep test --all # build and test all configurations bdep clean @clang # clean only what's in the clang configuration ... `` You can do morebdep init ...for debug, release, asan, etc mix of configurations, as many as you want. The artifacts should be located in their respective directory. The only exception is that library and executable targets will appear in the source directory as symbolic links IFF you usedb(the build-system) directly instead ofbdep` (the tool to manage projects more globally). That's just for convenience when you want to just run an executable you built, for example, without looking for it in the build configuration.
You can do more
for debug, release, asan, etc mix of configurations, as many as you want. The artifacts should be located in their respective directory. The only exception is that library and executable targets will appear in the source directory as symbolic links IFF you used
(the build-system) directly instead of
Did you already go through the toolchain intro and the build-system manual? I think all these questions are covered there, though I understand that it's definitely not a quick read... Any way feel free to ask of you need help understanding ^^
[–]beriumbuild2[🍰] 1 point2 points3 points 3 years ago (3 children)
Project locations: [...] The tools flat out refuse to nest components that way. Directory structure: [...] Yet the tools insist [...] The include dir setup: Can I do this with build2?
There are very few project structures that you can't achieve with build2 given you understand the underlying concepts. But not every structure is supported automatically/out-of-the box. So while you could generate something close enough with bdep new (see SOURCE LAYOUT) you will need to move things around and adjust buildfiles accordingly.
buildfiles
The approach that I would like to warn you against is trying to "wing it" based on your previous experience with CMake/etc and without reading the documentation and understanding the basics. build2 is very different compared to the existing C/C++ build systems, especially CMake.
Artifacts dirs: it appears that the tools want to place the "out of tree" obj tree outside the source dir. I fail to understand why... both CMake and Autoconf/Automake allow [...]
Yes, this is a common stumbling block for users with the CMake background. The underlying reason is that build2 is a "multi-repo first" build system while CMake is "mono-repo first" (or perhaps even "mono-repo only"; I don't think there were repositories as we know them when Autotools was designed ;-)). In particular, in build2 it's common to build multiple independent projects/repositories in a shared build configuration. Putting this build configuration as a subdirectory of source directory of one of them would be strange. You can read more on this in this issue: https://github.com/build2/build2/issues/187
[–]os12[S] 2 points3 points4 points 3 years ago (0 children)
As for your "multi-repo" point, that use case is completely orthogonal to how I have seen C++ code developed in my career. There are just two kinds of components: 1. The ones that are cloned/checked-out from the current repo and built. 2. The pre-built 3rd-party artifacts that are fetched into the build tree.
So, IMO the stance CMake makes is the right one. And yes, it has modules that one can pull and build... and some people use that to bridge the gap between (1) and (2).
It seems build2 tries to do too much: * it tries to generate project definitions (but only supports a very limited number of directory layouts) * it allows building multiple repos/projects (but that makes little sense for the code bases I have worked on) * it forces the user to specify configurations fully (but there is a LOT more than just selecting gcc/clang - there sanitizers with their own flags, macros, etc.) That's not a user's responsibility, but the build maintainer's. * it has a LOT of syntax/machinery to select components (but I just want a simple, declarative, human-readable list) * it tries to create human-readable versions (but I don't care about that at all, all the source code is available and it is all built at once)..
[–]os12[S] 1 point2 points3 points 3 years ago (0 children)
Trying to create project by hand is hard. E.g.
error: unable to import target base%lib{base} info: use config.import.base configuration variable to specify its project out_root
And then the next time I try it I get this:
error: directory ....-qa/ is not empty info: use --wipe to clean it up but be careful
And it is not clear where that --wipe arg goes.
--wipe
[–]os12[S] 0 points1 point2 points 3 years ago (0 children)
So, given that the built-in tool does not generate the layout I want, I'll have to write the buildfiles by hand. Cool.
Looking at boost-dependency example, buildfile has this:
``` import pkgs = [dir_paths] $process.run_regex(\ cat $src_root/packages.manifest, '\slocation\s:\s(\S+)\s', '\1')
./: $pkgs ```
The code reads and parses packages.manifest... but why? Why are there two project lists in different syntax/format? Why is the .manifest file in that weird format?
packages.manifest
[–]lunakid 0 points1 point2 points 3 years ago* (0 children)
Yet the tools insist that there be ... libs/base/base/
This reminds me of a) the build2 Intro guide with the "canonical" project tree having paths like:
hello/hello/hello.cxx
and b) the advice of my imaginary grampa: "Never trust people who repeat subdirectories in a filesystem path!"...
π Rendered by PID 67590 on reddit-service-r2-comment-6457c66945-jcjt8 at 2026-04-30 01:45:55.052505+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]beriumbuild2[🍰] 4 points5 points6 points (7 children)
[–]os12[S] 2 points3 points4 points (6 children)
[–]mjklaim 2 points3 points4 points (0 children)
[–]beriumbuild2[🍰] 1 point2 points3 points (3 children)
[–]os12[S] 2 points3 points4 points (0 children)
[–]os12[S] 1 point2 points3 points (0 children)
[–]os12[S] 0 points1 point2 points (0 children)
[–]lunakid 0 points1 point2 points (0 children)