The question is in the title.
So far I've only used IntelliJ for Java. Do I need to download some sort of Compiler or how can I create C++ files?
Like #dddavid said,there is an IDE made by JetBrains for C/C++ called Clion.
It is quite easy to use if you are familiar with intelliJ
However, if your question is how to compile and run C/C++ in intelliJ, there are still ways for you! (Which is not recommended if you are trying to develop large project in C/C++ in intelliJ.)
If you really want to do that, there is a terminal in intelliJ.
If you are in linux system, try to get gcc for C and g++ for C++.
If you are in windows system, you can try to get mingw or other compilers for C/C++.
After getting the compiler, you could simply type commands in the terminal inside intelliJ to compile C/C++ and run it.
For example, if you are in linux with g++, if you wants to compile main.cpp:
Follow these step:
type g++ main.cpp in the terminal inside intelliJ
type ./a.out in the terminal inside intelliJ
And it will start to run your C/C++ program!
You should use CLion instead. It's the JetBrains IDE for C/C++.
Related
I am a beginner to Ubuntu and Linux. I'm attempting to run just a simple hello world code and every time I run the C++ code in visual studio, it doesn't actually run, it opens to a new file called settings.json (which is empty).
If anyone can help me sole this problem that would be great, thank you.
I am a beginner to Ubuntu and Linux.
Read about the Unix philosophy.
It is favoring the command line and combination of simple tools
(e.g. in a command pipeline for your unix shell in some terminal emulator). A successful command (e.g. cp(1), used to copy files, or g++(1), a C++ compiler, or man(1) to read documentation, and od(1) or less(1) to inspect a file, or ls(1) to list them) often stays nearly silent when successful; see intro(1). Be aware of syscalls(2) (see also intro(2)). Remember that some parts of your C++ code could be generated (by metaprogramming tools such as ANTLR, swig, or GNU bison or GNU autoconf or GPP, or your own Guile, Python or GAWK or GNU bash script, or some other C++ program, etc...). See also Linux From Scratch. Every executable and process (except /sbin/init) is started by execve(2) with fork(2). See also ps(1), top(1), pstree(1) and proc(5).
Your C++ compiler could be GCC (or else Clang). Be sure to read the documentation on invoking GCC, and about your C++ preprocessor (perhaps GNU cpp). Try g++ --version then g++ --help in some terminal emulator.
If that command works, compile your HelloWorld.cpp with all warnings and debug info, so run in your terminal g++ -Wall -Wextra -g HelloWorld.cpp -o HelloWorld; you later run the obtained executable using ./HelloWorld in the same terminal (read about the $PATH variable in environ(7) and try the printenv(1) command).
Of course, you'll use some IDE or source code editor (e.g. Visual Studio Code, vim or GNU emacs or geany). Be sure to take some time to read its documentation. You'll configure them to run some build automation tool. You surely want to use some version control system, such as git.
And you'll need a debugger such as GDB.
Later, you'll want to use some build automation tool to drive your compilation commands (of several translation units) and the linking command (part of GNU binutils). Consider for your build automation using GNU make or ninja or many others.
Read of course Advanced Linux Programming and some good C++ programming book (and reference website). Be aware that C++ is a very difficult and complex programming language (see its spec n3337).
You could enjoy reading some textbook on operating systems. Study for inspiration the source code of existing open source C++ programs (e.g. on github), such as the fish shell.
You cannot just run the file. The simplest way is to open the command terminal and find where your file is located, the path that it is stored in and type in g++ fileName.cpp, make sure to name it with a cpp extension.
It is possible to compile and run C/C++ programs from Visual Studio Code.
To compile and run C/C++ programs from Visual Studio Code (vscode) you need to install C/C++ Compile Run extension from danielpinto8zz6 in Visual Studio Code.
After installing the C/C++ Compile Run extension press F6 to compile and run C/C++ Program.
Hope it helps !
I'm working on developing my own programming language, and to generate executables I wished to convert the source to C++ and the run it through a C++ compiler.
Does anybody know of a C++ compiler which I can simply include with my application and then invoke from the command line without installation?
I'm using Windows.
Thanks in advance, Tom.
Edit:
It seems gcc is the way to go and it would be a pain to set up, would people recommend bundling the installation file instead and then installing the compiler as part of the installation of my program?
Have you tried gcc (the windows port)?
Over the last couple of months I practiced console programming with Java just with the help of JDK and a text editor of my choice (Notepad++). And I loved the simplicity as a program can be compiled from the command line plainly using javac and run using java.
Now, I'm looking for similar compiler for C/C++, such that I create a .c or .cpp file and compile it in the command prompt, and all it does is create a "native" executable that can be run directly from the command prompt. Thus, without any need of bloated IDE. The reason I'm looking for such simple compiler is because it is going to be used by high-school students so I'm advised to avoid any IDE as far as possible, so students can practice all the concepts of C/C++ languages without having to go for IDE. Which compiler can I use that does this job? also, I must work across all the versions Windows starting from Windows XP.
You can download MinGW which is basically GCC for windows.
Then you can simply gcc somefile.c to create an executable.
http://gcc.gnu.org/gcc is a multi platform c/c++ compiler
Visual Studio includes the ability to compile from the command line. Like others just said you can look at cygwin/MinGW. I would recommended using Code::Blocks or Dev-C++. I know you stated you do not want an IDE, but I would highly suggest a minimalist IDE like the ones I just suggested, or at least SciTE or Notepad++ to get some basic syntax highlighting with the ability to configure build tools if you want as well.
MinGW GCC is definitely the way go, but I would recomend the nuwen.net distro (http://nuwen.net/mingw.html). Haven't used it in a while (yay unix!), but if IIRC, it comes with everything ready to go after unpacking. The official distribution is ... very hard to get working.
A very simple solution woul be cygwin and MinGW, which provides an environment very similar to a UNIX shell. Then you can use the make utilities to compile your program.
You should certainly consider using MinGW GCC, but not by download from the MiNGW web page, unless you are some kind of masochist. Get the one packaged by Twilight Dragon Media at http://tdm-gcc.tdragon.net.
I too use VisualStudio on Windows from the command prompt and use VS Make files as well. That way, I can smb mount my source code from a different machine and perform compiles on several different platforms at once (e.g. Windows, Linux, Solarsi).
I'm starting to learn C, and installed the eclipse plugin for C/C++ development (the CDT plugin). I'm testing the setup with a hello world program, but it looks like the eclipse C plugin (CDT) doesn't have a compiler built in. I thought eclipse plugins were usually self-sufficient? Do I need to install a compiler separately to complete my c setup, or how do I get it to compile from within eclipse.
I did the usual: created a new c project in the eclipse workspace, created a new hello.c file that looks like this:
/*
* hello.c
*
* Created on: 2009-12-21
* Author: geek
*/
main(){
printf("hello world\n");
}
Edit: OS is windows Vista
Can someone suggest a compiler that's known to play nice with eclipse (or a tutorial that you've used yourself to get this sorted out)
Probably the easiest way to get started with C programming on Windows is to install the free Visual C++ Express Edition. It comes with a compiler built-in, and unless you really want to use Eclipse for some reason, it's probably the least friction option.
On OS X, you can install Xcode from your installation CD to get the gcc compiler, or in [Li|U]nix you probably already have gcc installed. If you're on Windows check out MinGW. Thats a free C/C++ compiler based on gcc.
You need to have a compiler installed separately. Here is a CDT/compiler installation guide for different operating systems.
I would like to know what I should use to compile in C. I am brand new to programing in general and would greatly appreciate a comprehensive explanation of this process. I am on Windows Vista.
I heard about something called "djgpp" that is free and effective for windows.
For the answer to this question and many others you may have as you start out, try [this website][1] which has beginner tutorials. [Here's the page][2] on compilers and getting set up. An excerpt on what compilers you can use:
Windows/DOS
Code::Blocks and MINGW
Borland
DJGPP
Dev-C++ and Digital Mars
Windows Only
Microsoft Visual C++
nix
g++ is a C++ compiler that comes with most *nix distributions.
gcc is a C compiler that comes with most *nix distributions.
Macintosh
- XCode
Personally, I'd also recommend you strongly to read [The C Programming Language by Kernighan and Ritchie.][3] It will really help you understand both core principles of programming as well as C-specific details.
[1]: http://www.cprogramming.com/tutorial/c/lesson1.html
[2]: http://www.cprogramming.com/compilers.html
[3]: http://www.amazon.com/C-Programming-Language-2nd-Ed/dp/0131103709/ref=ed_oe_h
Visual Studio Express is a free version of Microsoft's leading IDE for Windows, and it includes a C development environment (editor, compiler, debugger).
Depends on which platform, but on Linux, Mac OS X and similar (including Cygwin), gcc is most common.
Say I have a script named myapp.c:
#import <stdio.h>
int main(){
printf("Hi!\n");
return 0;
}
To compile it from the command line using gcc is very simple, just run:
gcc myapp.c
..that outputs the binary as "a.out" (the default filename). To run the compiled app, just do..
./a.out
#which outputs: Hi!
Or put it somewhere within your $PATH (for example, /usr/bin or ~/bin/) and run a.out
You can specify the output filename with the -o flag:
gcc myapp.c -o myapp
./myapp
# output: Hi!
As for more complete guides, "Learn C for Cocoa" is a good, quick guide on the C language, and covers compiling. If you're interested in learning ObjC, the next part of the guide is also great.
On Windows, I would recommend looking into Visual Studio, specifically the Express editions (which are free).
There's no "Visual C", but the Visual C++ edition will compile C code (since C++ is an extension of C). There's also an option to "Compile as C code" somewhere in the build options.
Finally, The C Programming Language book covers, well, everything.
I would recommend using gcc and getting comfortable with the command line, if you plan on doing C for any extended amount of time. *nixes probably have it built in, and on Windows you can install MingW GCC and use it the same way.
I find this helpful because I feel like C was designed hand-in-hand with Unix, so it's better to stick with the command line than use an IDE off the bat. Most tutorials will probably assume you are using gcc. Also, if you're just learning C with gcc, you just type gcc -o outputfile sourcefile.c, whereas if you're starting with an IDE you'll have to figure out how the IDE works.
On the learning front, definitely pick up Kernighan and Ritchie's "The C Programming Language" as it's the definitive book on C. Rather slim volume, and easy to read.
Just a note, another helpful compiler flag for gcc is -g, as in gcc -o output -g -Wall sourcefile.c. -g enables debugging symbols, which will be useful in the future when you want to start debugging with gdb. This is another reason why you should start with gcc rather than an IDE, it makes it easier to move on to gdb.
You could always use MS Visual C++, but I think it's too complicated for a beginner. I personally recommend Notepad++ for editing as it doesn't do too much for you, but it formats the code nicely. Of course, once you become more experienced you might want to move on to a full-blown IDE with project management and such (or better yet, emacs ;)) but when you're just starting out simpler is probably better.
If you're on Unix (i.e. Linux, Mac OS X, FreeBSD, Windows under Cygwin, etc.) I recommend the GNU Compiler Collection (gcc). To compile a file hello.c, run this at the command prompt:
gcc hello.c
This compiles hello.c to the executable a.out. If you want a better-named executable, try this:
gcc -o hello hello.c
This compiles hello.c to the executable hello. Some more helpful flags:
gcc -Wall -Wextra -o hello hello.c
This turns on lots of helpful warnings that will probably help you catch bugs in your code.
On Windows, many people use Microsoft Visual C++, but I have no real experience with Windows. As I referenced above, you can install Cygwin, and then use the above steps, but many prefer pure-Windows compiling. Also, MinGW is a native-Windows port of gcc. It's all a matter of preference, though.
Welcome to programming!
You might want to start in the right track and install a copy of Linux in your box. Try Ubuntu cuz it's easy to install and learn
Next learn to use the console! It will help you so much in the next years.
Once ubuntu is installed you need to install C compiler and basic libraries just typing in the console
sudo apt-get install gcc build-essential
Then just create a C file and run
gcc myprogram.c -o myprogram
This will generate an exec file called yourprogram, run it using
./myprogram
Here are some useful links:
Ubuntu Home
Compiling/Running C in Ubuntu Forums
Linux Tutorial - READ THIS!
I would recommend downloading Microsoft Visual C++ Express Edition. http://www.microsoft.com/express/vc/ DJGPP will work as a compiler but does not provide an editor or coding environment. Compiling your code involves going to the command line. Some have suggested using gcc or MinGW but both of those programs behave similarly to DJGPP. Using a separate editor and compiling your code from the command line is not really the way that software is typically written in a Windows environment. Visual C++ will allow you to write and compile either C or C++ code.
Microsoft Visual C++ is a free of cost development environment which includes an editor and a compiler. Simply download the installer executable and run it to install. The installer will download the necessary software from the Internet and install it on your computer. The installer will download about 200MB of software so it may take up to an hour to download depending on your connection speed.
Once you have Visual C++ installed, start a new project and write your code. You can then compile and build it right from inside Visual C++ and see the output. Start by writing a simple command line program and then work up to more interesting programs.
For windows now you can use gcc as mentioned above but also MSC. You can get the compiler for free with the Visual Studio Express bundle for Visual C++ Express
Invoking the compiler from the command line is fine for small apps as you're getting used to the C syntax, but as you move along, you will find that entering the myriad options gets tedious, and you will want to use a build tool. make is a basic but powerful way of compiling your projects easily. Editing makefiles by hand can be tedious, and will get in the way of your learning, so I'd suggest skipping right over that and go for the autotools toolchain.
Ok Josiah, first of all, be sure to have a C compiler installed on your system. On Linux, Mac, there's a compiler installed just out of the box, called the GCC compiler. And on Windows, you need to instal one, I recommend you to instal an IDE (like devshed) that includes an editor, compiler, debugger... all that you need to develop a C/C++ application.
In order to compile over Linux/Mac, first of all you'll need a source file (a text file with your code) and save it with a .c or .cpp extension. Then open your terminal and type:
gcc <fileName.c>
You should replace <fileName.c> with your filename (the full path, or first go to the files location and just type the file name).
This will create a .o file (and object file) in the same path of your source file, this is the executable file for your computer!
On windows, if you already installed an IDE, is easier, you just click the compile button and there ya go!
I hope this to be helpful to you