Sublime Forum

How to build and run C++?

#1

How to set up sublime text for C++? It’s annoying to make input.in and output.in every single time I am creating C++ project. So is here any simple way to build them? However when I build them, I can’t put input there. And I can’t build and run the exe file into terminus instead of the console/something Sublime text uses to show output. And even I can’t build two files into one executable file. Also it’s not easy way to run and make C++ from command line/terminus(sublime text terminus package) by using gcc command. Is here any way to have a terminal as Eclipse ide? However I also want to know the build system to build them (it’s hard to learn the build system documentation, so it would be helpful if someone says the build system code :thinking::thinking::thinking::upside_down_face::upside_down_face::upside_down_face:)

0 Likes

#2

If you want a terminal that’s built directly into Sublime, you indeed want Terminus. Can you clarify what you mean by:

A simple build such as:

{
    "target": "terminus_exec",
    "cancel": "terminus_cancel_build",
    
    "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++",

    "variants":
    [
        {
            "name": "Run",
            "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    ]
}

Would allow you to compile a single file C++ program or (using the variant) compile and then execute it. Both would execute in a Terminus panel and allow you to enter input if you wanted to.

Not knowing how to build two files into one executable sounds like you’re not familiar with using the compiler in general. There’s nothing magic about how to make a build system that does that; all else being equal a build system just replicates automatically the steps you would take manually to compile and run a program, which requires you to know how to do so manually.

I have some videos on build systems and how they work that may help if you want to know more about how to make them though: https://youtube.com/playlist?list=PLGfKZJVuHW91WyVIitRhcTPD1PTFIPsia

0 Likes

#3

Oh thanks @OdatNurd. Btw I mean that when I build C++ file using the sublime C++ build system, it shows the output in console instead of terminus. But now I understand why the output came to console instead of terminus. And thanks for the video link!

0 Likes