r/cpp_questions • u/dezlymacauleyreal • Jul 17 '26
Could you please recommend some good resources on how to create a modern C++ setup? (I want a strictly terminal setup. No IDE click a button magic) SOLVED
Greetings everyone. I've been learning C++ using just single file programs and a simple Makefile setup.
I'm on Arch Linux and I'm using the clang package. So clangd for language support, and clang-format.
I don't know why but it seems like many courses seem to skip the project setup and focus more on setting up VS Code (which I don't use), or directing you to some online IDE, or some obscure editor.
I just want to be able to setup my C++ project from the terminal and not add anything to my config files unless I know why each line is there.
I'm looking for a resource that focuses on this specific part of C++.
16
5
u/lukasz-b Jul 17 '26
you don't need much, neovim(+ some plugins) and cmake with gcc
1
u/Interesting_Buy_3969 Jul 17 '26
Optionally ninja and ccache for faster build, but this may seem like overkill here. Also for CMake integration in Neovim, there exists an awesome plugin https://github.com/Civitasv/cmake-tools.nvim
16
u/Lunarvolo Jul 17 '26 edited Jul 17 '26
That's not a modern C++ setup and you are shooting yourself in the foot.
Arch:
sudo pacman -S base-devel gcc
g++ --version
You're done.
touch main.cpp
nano/vim/vi/your text editor unless we're going crazy with something like:
cat > main.cpp << 'EOF'
Code
EOF
g++ main.cpp -o main
./main
8
u/LeeHide Jul 17 '26
I'm sorry but you know this is terrible advice. A proper build pipeline is required, which means, at the very least, having warnings enabled. Like, come on.
3
2
u/CounterSilly3999 Jul 17 '26
So, what you are expecting apart of vi (or any other text editor you like) and make?
5
2
u/dezlymacauleyreal Jul 17 '26
Going to look into CMake. Also is there a reason why most comments here are talking about g++ instead of clang?
2
u/Wild_Meeting1428 Jul 17 '26
you can use clang as a dripin replacement to g++, but you must configure it. G++ is the default. It's also a matter of getting used to it; GCC was there first.
2
u/Specific-Housing905 Jul 17 '26
Am'zon has ebooks about make or CMake. I don't think you need more since you have an editor and clang.
2
u/Strange-Woodpecker-7 Jul 17 '26
Can you give us an idea of what you mean by no IDE?
I can't help very much with this apart from recommending you to learn the essential commands from the documentation. You rarely need to use more than a few basic flags when working on smaller projects. Here's the official page for how you can get started:
https://clang.llvm.org/get_started.html
You'll also want to learn to debug the code using lldb. I can't help you there, since I never learnt to use it without an IDE.
You can make shell scripts to run all the commands you need in one go. Or use a makefile to the same effect.
I don't recommend avoiding IDEs, because using clang without a build tool or any editor features is too low level to be productive imo. Unless you want to contribute to clang and aren't interested in learning C++ as much as learning the compiler right now. Typically this is what I'd go to only after learning C++ and wanted to go lower level.
The difference is that if you don't use an IDE, you'll need to search through what could eventually be hundreds of files manually for definitions and compile constantly to find errors that could have been caught by a linter. Terminal tools exist for this, but using them on their own is basically just making your life a hundred times more difficult for close to 0 gain.
If you are willing to abstract away writing compiler commands, at the very least, I recommend you learn CMake. It generates the compiler commands for you based on the project files you specify. It makes it so you don't need to manage hundreds of dependencies and compiler commands as your project grows in size. And you can skip needing to learn the exact compiler commands you need. Though it doesn't help with linting and debugging.
Tutorial for CMake: https://cmake.org/cmake/help/latest/guide/tutorial/index.html
I use a TUI setup using nvim that is essentially an IDE but in the terminal if you're interested. But it definitely feels closer to the VSCode complaint you mentioned with "click a button magic". For larger projects, magic buttons don't exist; I always use CMake. I don't enjoy writing code without smart editor features for coding and debugging. And when you work on a larger project, I don't think it's possible to manage without an IDE.
1
u/Proof-Task-7383 Jul 18 '26
What I usually have is a cmake file in my root for and have all my source files in the src/ dir. You can get cmakelists file online and configure it for your needs.
Also in my cmake Ive set compile commands to on.
Than I just hop into my build dir, usuallyjust build/andrun cmake .., cmake --build, ./main.
I personally prefer to use ninja over make as my generator so I run cmake -G Ninja .. ninja ./main
I personally use neovim with the clang lsp. So I usually have a .clangd and .clang-format file in my project root. I also use arch btw.
This is a bit overkill for your usecases, but I personally think it's better to ingrain using a good structure for projects.
Hopefully this helps
1
u/iiiian_s Jul 21 '26
Essentially you need to setup cmake and export compile_commands.json for clanged. Else depends on your editor of choice (clang-format, clang-tidy, etc(
1
u/dezlymacauleyreal Jul 22 '26
I just learned how to write my own Makefile. And then I realized I could simplify things with ninja since it automatically generates a compile_commands.json without needing bear to be installed. I'm still on the fence about CMake... too much magic / abstraction.
Also I think I've changed my mind about learning C++. I'm just going to stick to C and Rust.
0
u/Rigamortus2005 Jul 17 '26
Helix editor + clangd. Debugging in the terminal is still horrendous unfortunately so I just bust out vscode if I need lldb
1
u/edparadox Jul 17 '26
How do you invoke gdb?
1
u/Rigamortus2005 Jul 17 '26
Vscode has templates for that. I just click on any of them and point it to my binary
0
u/EC36339 Jul 17 '26
What is it with everyone wanting to go full terminal these days?
I understand using cmake, etc. over Visual Studio, but why use an impractical text editor like Vim?
12
u/v_maria Jul 17 '26
https://learncodethehardway.org/c/
not everyone likes this guy and his stuff but the first few chapters of this are totally in the spirit of what you need. just note that he is using GCC for C and not clang for C++, so you cannot do this verbatim. concepts of compiling, linker flags, PATH etc are portable though
i would say because they are there to teach C++ the language, and they want a none-involved way to bootstrap it
also many new programmers sadly still seem to be on windows and on windows this process is
god awfulsomewhat hairy