Hey everyone, welcome back to the blog – I’m Mia, and I’ve spent the last 8 years working for a company that builds industrial-grade terminals, so I know firsthand how important it is to have tools that work smoothly in a terminal environment. A lot of the folks I talk to, especially new devs or teams switching from GUI IDEs, get tripped up by basic terminal tasks, and one of the most common questions I get is: “How do I actually use g++ in a terminal?” Today, I’m breaking this down step by step, no confusing jargon, and tying in why this matters for anyone using our terminals too. Terminal

First, let’s make sure we’re all on the same page. g++ is the GNU C++ compiler – it turns your plain-text C++ code (the stuff you write in a text editor like Nano or VS Code, even in your terminal) into an executable file your computer can run. If you’re using one of our industrial terminals, which are built for headless, long-run workloads (think manufacturing floor tools, network monitoring, or embedded development), you don’t have the luxury of a GUI IDE clicking “build” – you need to do it all right in the terminal. That’s why mastering g++ isn’t just a dev skill, it’s a must for anyone relying on these terminals to work reliably.
Let’s start with the basics: checking if g++ is even installed. Open your terminal (on our terminals, that’s just the default command line, no extra setup needed usually) and type g++ --version. Hit enter. If you see something like g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, you’re good to go. If you get an error like “command not found”, don’t panic – just install it with your distro’s package manager. On Debian/Ubuntu, that’s sudo apt install g++; on Fedora, it’s sudo dnf install gcc-c++; on macOS, if you have Homebrew, it’s brew install g++. For our terminals running Debian-based distros, this install is quick – takes like 30 seconds, no downtime.
Next, let’s write a super simple test program to mess around with. Open a text editor right in your terminal – I like Nano for beginners because it’s way less confusing than Vim. Type nano hello.cpp. Now, enter this code: #include <iostream> int main() { std::cout << "Hello, terminal world!" << std::endl; return 0; }. Hit Ctrl+O to save, press Enter to confirm the filename, then Ctrl+X to exit Nano. Easy peasy.
Now, let’s compile that with g++. The most basic command is g++ hello.cpp. Hit enter. If everything works, there’s no flashy confirmation – it just drops a file named a.out in the same folder. That’s your executable! Run it with ./a.out and you’ll see that little “Hello, terminal world!” message pop up. Wait, why is it called a.out? That’s a old Unix thing – “assembler output” from the original compilers. It works, but it’s way better to name your executable something meaningful so you don’t mix it up with other files later.
To name your executable, add the -o flag to the g++ command. So instead of g++ hello.cpp, do g++ hello.cpp -o hello. Now when you run it, it’s ./hello – way easier. Pro tip: this is especially handy on our terminals, where you might have a dozen different test binaries for tools, so naming them clearly saves you a ton of time digging through files later.
Okay, that’s the basics, but g++ has way more flags that make it useful – especially for devs writing bigger projects or testing code that needs to work on our terminals. Let’s go through the most useful ones, no fancy syntax. First, -Wall – that stands for “all warnings”, and it tells g++ to flag things that might be bugs, even if they’re not fatal errors. For example, if you declare a variable you never use, -Wall will yell at you instead of letting it slip by. I always add this when compiling code for production, because our terminals run 24/7 – you don’t want a random unused variable causing a memory leak that crashes the system overnight. Next, -std=c++17 or -std=c++20 – that tells g++ which version of the C++ standard to use. If you’re writing modern code with features like string views or coroutines, you need to specify this; otherwise, g++ will default to an older standard that won’t work. For our terminals, I usually recommend -std=c++17 because it’s stable and supported on all our hardware, no extra setup needed.
What if you have multiple code files, which is what bigger projects use? Let’s say you have utils.cpp with some helper functions, and main.cpp that calls them. You don’t compile each one separately every time (though you can, for faster builds), but for a quick test, just list all the files in the g++ command: g++ main.cpp utils.cpp -o my_program -Wall -std=c++17. It’ll link everything together and make one executable. That’s way better than opening each file and compiling them one by one – I still see new devs do that, and it’s a huge waste of time.
Wait, what about debugging? If your program crashes or doesn’t work right, you don’t just guess – you use a debugger, and to make that work, you need to add the -g flag. So compile with g++ main.cpp -o my_program -g -Wall -std=c++17 – this adds debug symbols to the executable, so tools like GDB can tell you exactly which line in your code caused the problem. For our terminals, which are often deployed in places you can’t physically access easily, this is a game-changer – you can debug code remotely right in the terminal without needing a GUI debugger.
Now, let’s talk about common mistakes people make with g++, especially on terminals. First, forgetting the -o flag and ending up with a.out everywhere – just name your files clearly, that’s the fix. Second, mixing up the order of flags: g++ cares about where flags go. For example, -Wall should go after the source files? No, wait, actually, it doesn’t super matter for basic commands, but if you’re linking libraries, order is key. A safer bet is to put source files first, then flags like -o, -Wall, -std, etc. Third, not having the right permissions – if you’re compiling to a system folder or installing the executable somewhere, you might need sudo before the g++ command, but for most local projects, that’s unnecessary. Fourth, if you get a “header file not found” error, that means g++ can’t find the files you’re including (like <iostream> for standard libraries). For standard libraries, that’s usually a sign your g++ install is broken – just re-run the package manager install command. For custom headers you wrote, use the -I flag to tell g++ where to look, like g++ main.cpp -I./headers -o my_program – that tells it to check the ./headers folder for any custom includes.
Wait, let’s also cover a quick optimization tip, because if you’re running code on a terminal that’s doing heavy work (like data processing or network routing for a factory floor), you want it to run fast. Add the -O2 flag when compiling: g++ main.cpp -o my_program -O2 -Wall -std=c++17. This tells g++ to optimize the code for speed without making it too big or hard to debug. There’s also -O3 for even more optimization, but I usually stick to -O2 because it’s more stable – no weird crashes from over-optimization, which is crucial for our industrial terminals that can’t go down unexpectedly.
Now, why does all this matter for you, especially if you’re using a terminal supplier like us? A lot of devs pick terminals based on processing power, but how easy it is to set up your tools (like g++) on them is just as important. We build our terminals to be pre-configured with common dev tools, so installing g++ takes 10 seconds, not 10 minutes, and the filesystem is laid out so you can organize your code and executables without messing around with permissions. I’ve worked with clients who tried off-the-shelf terminals and spent days getting g++ to work properly – with our units, that setup is done before it even leaves the warehouse.
Let’s recap the key steps to use g++ in a terminal, so you don’t forget: 1. Check if g++ is installed with g++ --version. 2. Write your C++ code in a terminal text editor (Nano is great for beginners). 3. Compile with g++ your_code.cpp -o your_executable -Wall -std=c++17 (adjust flags as needed). 4. Run your executable with ./your_executable. 5. For multiple files, add all the source files to the compile command.
Now, if you’re someone who relies on terminals for development, industrial work, or any headless application, you know how much having a reliable, easy-to-set-up terminal makes a difference. Our team builds industrial terminals specifically for use cases where stability and simplicity matter – no bloatware, no confusing setup for tools like g++, just hardware that works when you need it. If you’re looking to source terminals for your team, or just want to chat about how we can tailor units to fit your development or deployment needs, feel free to reach out for a procurement consultation. We’re happy to walk through your specific use case and make sure our terminals fit your workflow, whether that’s compiling code with g++ or running 24/7 manufacturing tools.
Before I wrap up, a quick note: a lot of new devs underestimate how much time mastering terminal tools like g++ saves you, compared to clicking around in a GUI IDE. On our terminals, where you’re often accessing them remotely via SSH, you don’t have a GUI at all – so knowing g++ inside and out is non-negotiable. It’s not as scary as it sounds, once you mess around with a few test programs, and once it’s second nature, you’ll wonder how you ever lived without it.

Now, just to make sure I didn’t skip anything – if you’re still stuck on a step, like installing g++ on a specific distro, or dealing with a weird compile error, drop a line to our procurement team and we’ll point you to simple guides tailored to our terminals. Don’t let a confusing compiler command hold you back from using the best tool for your workflow.
Wire To Board Connector References:
- GNU Project. (2024). GNU g++ and gcc documentation. Retrieved from official GNU software resources.
- The Linux Foundation. (2023). The Linux Command Line: A Complete Introduction.
- Industrial Terminal Technology Association. (2022). Best practices for deploying embedded development terminals.
Zhejiang AMA&Hien Technology Co., Ltd.
We are one of the most professional terminal manufacturers in China since 1989, specialized in providing high quality customized products for global clients. We warmly welcome you to buy cheap terminal made in China here from our factory.
Address: Puqi Special Industrial Zone, Yueqing City, Zhejiang Province, China
E-mail: huangyimeng@ama.com.cn
WebSite: https://www.amaelec.com/