+ 2
Compile and Run C++ Program on CLI without IDE
So I had a question about C++. Specifically outputting to the console Code::blocks sets up the console application project for me. But how do I set it up myself? I barely know about any of this. In fact, I really only know how to run it by pressing "run" in code::blocks. Let's say i'm coding in VSC(Visual Studio Code) I can write the code and save it as a cpp file. But if I try to run it, it just opens VSC. How would I get it to output to the console without relying on an IDE to set up the project for me? Sorry for the long question.
10 Respostas
+ 2
To put things short:
Write a hello world program in c++ (any text editor will do).
Save it to a file with a .cpp extension
Run cmd (or bash. im assuming you use windows)
Type 'g++ <filename.cpp>' (In my first answer, I told you how to setup mingw so you could run g++)
Then, type 'a.exe' (assuming you use windows)
+ 5
Daniel Cooper In the simplest sense:
You don't need an IDE to type code. You just need a basic text editor. To not rely on anything to set up and compile the project for you, would mean to compile it yourself using the cmd/shell/terminal, whatever you call your CLI.
+ 4
You need to have a compiler. Use g++ to run it. In cmd (which can be accessed in vs code), try doing g++ main.cpp (or whatever your file's name is). If it doesn't work then try adding {where you installed CodeBlocks}\MinGW to your PATH variable
+ 4
nonzyro Yeah I just stopped using windows this year. Linux is way better for me. But I use Ubuntu instead of Debian because my touchpad and wi-fi doesn't work on Debian.
+ 3
If you're on Linux/BSD, it's so simple. Open a CLI and type "g++ <your-file.cpp> && ./a.out" to compile and run it. Sadly I take it you're on Winblows.
Winkey+R opens the "Run" box. Then type cmd.exe and follow the instructions qwerty gave.
Personally I find Winblows a nightmare. I recommend a Debian PC for coding or a dual boot or a VM.
FYI: I haven't used an IDE in ages. I haven't used Winblows since 7. My life is better for it.
+ 3
Hatsy Rei I don't think that's what I'm asking. Lol
To simplify, I'm trying to figure out how to make a console application without code::blocks setting everything up for me.
Like, I don't want to rely on something setting up the project if I don't have to.
Is the compiler doing that?
And I'm a bit confused now guys. Don't we need an IDE to type code?
sorry if these are stupid questions
I'm extremely new to all of this lol
+ 2
Daniel Cooper A compiler is a program that makes your executable (.exe) based on the files and options you give.
It has nothing to do with setting up your project. If you press "run" on Code::blocks, it calls the compiler (g++) to make the executable (if it wasn't compiled already) and runs it. Without a compiler, you can't run your code.
+ 1
qwerty That's coz, by default, Debian is Free/Libre/OSS only. However you can use proprietory drivers by adding "non-free contrib" to your sources.list file. If it works on Ubuntu, then it will work on Debian. If you need wifi while installing, use the unofficial Debian + Firmware image: "firmware-[version].iso"
Ubuntu does make getting software easier, but I find it less stable than Debian Stable and a lot of its system infuriating (it has a Debian base, but works very differently).
It's a personal thing though. Many people find Ubuntu easiest. I find the opposite because of the era I grew up in (286 was my first PC).
+ 1
ok
That helped a lot. Thanks for the explanation.
0
If you have some old Visual Studio installed (I have version 12), you can compile a c++ program that you edited in any text editor using cl.exe (examlple: cl myprog.cpp). Make sure you set the variables using the supplied vcvars32.bat. You have to link myprog.obj to get myprog.exe.