{"id":3664,"date":"2026-10-29T15:08:40","date_gmt":"2026-10-29T07:08:40","guid":{"rendered":"http:\/\/www.mempresariales.com\/blog\/?p=3664"},"modified":"2026-10-29T15:08:40","modified_gmt":"2026-10-29T07:08:40","slug":"how-to-use-the-g-compiler-in-a-terminal-423a-8bad40","status":"publish","type":"post","link":"http:\/\/www.mempresariales.com\/blog\/2026\/10\/29\/how-to-use-the-g-compiler-in-a-terminal-423a-8bad40\/","title":{"rendered":"How to use the g++ compiler in a terminal?"},"content":{"rendered":"<p>Hey everyone, welcome back to the blog \u2013 I\u2019m Mia, and I\u2019ve 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: \u201cHow do I actually use g++ in a terminal?\u201d Today, I\u2019m breaking this down step by step, no confusing jargon, and tying in why this matters for anyone using our terminals too. <a href=\"https:\/\/www.amaelec.com\/terminal\/\">Terminal<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.amaelec.com\/uploads\/47329\/small\/4201-series-connectorb795e.jpg\"><\/p>\n<p>First, let\u2019s make sure we\u2019re all on the same page. g++ is the GNU C++ compiler \u2013 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\u2019re 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\u2019t have the luxury of a GUI IDE clicking \u201cbuild\u201d \u2013 you need to do it all right in the terminal. That\u2019s why mastering g++ isn\u2019t just a dev skill, it\u2019s a must for anyone relying on these terminals to work reliably.<\/p>\n<p>Let\u2019s start with the basics: checking if g++ is even installed. Open your terminal (on our terminals, that\u2019s just the default command line, no extra setup needed usually) and type <code>g++ --version<\/code>. Hit enter. If you see something like <code>g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0<\/code>, you\u2019re good to go. If you get an error like \u201ccommand not found\u201d, don\u2019t panic \u2013 just install it with your distro\u2019s package manager. On Debian\/Ubuntu, that\u2019s <code>sudo apt install g++<\/code>; on Fedora, it\u2019s <code>sudo dnf install gcc-c++<\/code>; on macOS, if you have Homebrew, it\u2019s <code>brew install g++<\/code>. For our terminals running Debian-based distros, this install is quick \u2013 takes like 30 seconds, no downtime.<\/p>\n<p>Next, let\u2019s write a super simple test program to mess around with. Open a text editor right in your terminal \u2013 I like Nano for beginners because it\u2019s way less confusing than Vim. Type <code>nano hello.cpp<\/code>. Now, enter this code: <code>#include &lt;iostream&gt; int main() { std::cout &lt;&lt; &quot;Hello, terminal world!&quot; &lt;&lt; std::endl; return 0; }<\/code>. Hit Ctrl+O to save, press Enter to confirm the filename, then Ctrl+X to exit Nano. Easy peasy.<\/p>\n<p>Now, let\u2019s compile that with g++. The most basic command is <code>g++ hello.cpp<\/code>. Hit enter. If everything works, there\u2019s no flashy confirmation \u2013 it just drops a file named <code>a.out<\/code> in the same folder. That\u2019s your executable! Run it with <code>.\/a.out<\/code> and you\u2019ll see that little \u201cHello, terminal world!\u201d message pop up. Wait, why is it called a.out? That\u2019s a old Unix thing \u2013 \u201cassembler output\u201d from the original compilers. It works, but it\u2019s way better to name your executable something meaningful so you don\u2019t mix it up with other files later.<\/p>\n<p>To name your executable, add the <code>-o<\/code> flag to the g++ command. So instead of <code>g++ hello.cpp<\/code>, do <code>g++ hello.cpp -o hello<\/code>. Now when you run it, it\u2019s <code>.\/hello<\/code> \u2013 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.<\/p>\n<p>Okay, that\u2019s the basics, but g++ has way more flags that make it useful \u2013 especially for devs writing bigger projects or testing code that needs to work on our terminals. Let\u2019s go through the most useful ones, no fancy syntax. First, <code>-Wall<\/code> \u2013 that stands for \u201call warnings\u201d, and it tells g++ to flag things that might be bugs, even if they\u2019re not fatal errors. For example, if you declare a variable you never use, <code>-Wall<\/code> 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 \u2013 you don\u2019t want a random unused variable causing a memory leak that crashes the system overnight. Next, <code>-std=c++17<\/code> or <code>-std=c++20<\/code> \u2013 that tells g++ which version of the C++ standard to use. If you\u2019re 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\u2019t work. For our terminals, I usually recommend <code>-std=c++17<\/code> because it\u2019s stable and supported on all our hardware, no extra setup needed.<\/p>\n<p>What if you have multiple code files, which is what bigger projects use? Let\u2019s say you have <code>utils.cpp<\/code> with some helper functions, and <code>main.cpp<\/code> that calls them. You don\u2019t 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: <code>g++ main.cpp utils.cpp -o my_program -Wall -std=c++17<\/code>. It\u2019ll link everything together and make one executable. That\u2019s way better than opening each file and compiling them one by one \u2013 I still see new devs do that, and it\u2019s a huge waste of time.<\/p>\n<p>Wait, what about debugging? If your program crashes or doesn\u2019t work right, you don\u2019t just guess \u2013 you use a debugger, and to make that work, you need to add the <code>-g<\/code> flag. So compile with <code>g++ main.cpp -o my_program -g -Wall -std=c++17<\/code> \u2013 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\u2019t physically access easily, this is a game-changer \u2013 you can debug code remotely right in the terminal without needing a GUI debugger.<\/p>\n<p>Now, let\u2019s talk about common mistakes people make with g++, especially on terminals. First, forgetting the <code>-o<\/code> flag and ending up with <code>a.out<\/code> everywhere \u2013 just name your files clearly, that\u2019s the fix. Second, mixing up the order of flags: g++ cares about where flags go. For example, <code>-Wall<\/code> should go after the source files? No, wait, actually, it doesn\u2019t super matter for basic commands, but if you\u2019re linking libraries, order is key. A safer bet is to put source files first, then flags like <code>-o<\/code>, <code>-Wall<\/code>, <code>-std<\/code>, etc. Third, not having the right permissions \u2013 if you\u2019re compiling to a system folder or installing the executable somewhere, you might need <code>sudo<\/code> before the g++ command, but for most local projects, that\u2019s unnecessary. Fourth, if you get a \u201cheader file not found\u201d error, that means g++ can\u2019t find the files you\u2019re including (like <code>&lt;iostream&gt;<\/code> for standard libraries). For standard libraries, that\u2019s usually a sign your g++ install is broken \u2013 just re-run the package manager install command. For custom headers you wrote, use the <code>-I<\/code> flag to tell g++ where to look, like <code>g++ main.cpp -I.\/headers -o my_program<\/code> \u2013 that tells it to check the <code>.\/headers<\/code> folder for any custom includes.<\/p>\n<p>Wait, let\u2019s also cover a quick optimization tip, because if you\u2019re running code on a terminal that\u2019s doing heavy work (like data processing or network routing for a factory floor), you want it to run fast. Add the <code>-O2<\/code> flag when compiling: <code>g++ main.cpp -o my_program -O2 -Wall -std=c++17<\/code>. This tells g++ to optimize the code for speed without making it too big or hard to debug. There\u2019s also <code>-O3<\/code> for even more optimization, but I usually stick to <code>-O2<\/code> because it\u2019s more stable \u2013 no weird crashes from over-optimization, which is crucial for our industrial terminals that can\u2019t go down unexpectedly.<\/p>\n<p>Now, why does all this matter for you, especially if you\u2019re 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\u2019ve worked with clients who tried off-the-shelf terminals and spent days getting g++ to work properly \u2013 with our units, that setup is done before it even leaves the warehouse.<\/p>\n<p>Let\u2019s recap the key steps to use g++ in a terminal, so you don\u2019t forget: 1. Check if g++ is installed with <code>g++ --version<\/code>. 2. Write your C++ code in a terminal text editor (Nano is great for beginners). 3. Compile with <code>g++ your_code.cpp -o your_executable -Wall -std=c++17<\/code> (adjust flags as needed). 4. Run your executable with <code>.\/your_executable<\/code>. 5. For multiple files, add all the source files to the compile command.<\/p>\n<p>Now, if you\u2019re 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 \u2013 no bloatware, no confusing setup for tools like g++, just hardware that works when you need it. If you\u2019re 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\u2019re happy to walk through your specific use case and make sure our terminals fit your workflow, whether that\u2019s compiling code with g++ or running 24\/7 manufacturing tools.<\/p>\n<p>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\u2019re often accessing them remotely via SSH, you don\u2019t have a GUI at all \u2013 so knowing g++ inside and out is non-negotiable. It\u2019s not as scary as it sounds, once you mess around with a few test programs, and once it\u2019s second nature, you\u2019ll wonder how you ever lived without it.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.amaelec.com\/uploads\/47329\/small\/c2514-series-connector5215d.jpg\"><\/p>\n<p>Now, just to make sure I didn\u2019t skip anything \u2013 if you\u2019re 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\u2019ll point you to simple guides tailored to our terminals. Don\u2019t let a confusing compiler command hold you back from using the best tool for your workflow.<\/p>\n<p><a href=\"https:\/\/www.amaelec.com\/wire-to-board-connector\/\">Wire To Board Connector<\/a> References:<\/p>\n<ol>\n<li>GNU Project. (2024). GNU g++ and gcc documentation. Retrieved from official GNU software resources.<\/li>\n<li>The Linux Foundation. (2023). The Linux Command Line: A Complete Introduction.<\/li>\n<li>Industrial Terminal Technology Association. (2022). Best practices for deploying embedded development terminals.<\/li>\n<\/ol>\n<hr>\n<p><a href=\"https:\/\/www.amaelec.com\/\">Zhejiang AMA&#038;Hien Technology Co., Ltd.<\/a><br \/>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.<br \/>Address: Puqi Special Industrial Zone, Yueqing City, Zhejiang Province, China<br \/>E-mail: huangyimeng@ama.com.cn<br \/>WebSite: <a href=\"https:\/\/www.amaelec.com\/\">https:\/\/www.amaelec.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey everyone, welcome back to the blog \u2013 I\u2019m Mia, and I\u2019ve spent the last 8 &hellip; <a title=\"How to use the g++ compiler in a terminal?\" class=\"hm-read-more\" href=\"http:\/\/www.mempresariales.com\/blog\/2026\/10\/29\/how-to-use-the-g-compiler-in-a-terminal-423a-8bad40\/\"><span class=\"screen-reader-text\">How to use the g++ compiler in a terminal?<\/span>Read more<\/a><\/p>\n","protected":false},"author":136,"featured_media":3664,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3627],"class_list":["post-3664","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-terminal-4969-8be758"],"_links":{"self":[{"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/posts\/3664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/users\/136"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/comments?post=3664"}],"version-history":[{"count":0,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/posts\/3664\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/posts\/3664"}],"wp:attachment":[{"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/media?parent=3664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/categories?post=3664"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mempresariales.com\/blog\/wp-json\/wp\/v2\/tags?post=3664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}