C++ for Ubuntu in Linux

Asked By 250 points N/A Posted on -
qa-featured

Hi,

I've recently got to Linux and I am quite loving it. I am currently using Ubuntu. My problem is I don't know of any visual studio for Linux. I have a assignment for my college for C++. Is it possible in Ubuntu or do i need to switch back to Windows? I see software like KDEV and CodeLite in the repository but I don't know how to use them. Please reply soon. Thanks in advance.

SHARE
Best Answer by shababhsiddique
Answered By 0 points N/A #91345

C++ for Ubuntu in Linux

qa-featured

Visual Studio is just a IDE (development environment) and it is only designed for Microsoft Windows. If you want to do C++ programming in Ubuntu or in any other Linux you are going to need a native compiler for that platform. In Ubuntu the compiler is g++. The most comprehensive and easiest way to install all the tools required to compile is by issuing the following command on the terminal:

Sudo apt-get install build-essentials

This is going to need your super user password. After the installation has succeeded, you can compile the code by:

G++ yourcode.cpp -0 output file

To execute the created file

. /Output file

[Assuming that you have written the code using any text editor and saved it as "yourcode.cpp" to your current directory.]

Answered By 250 points N/A #91348

C++ for Ubuntu in Linux

qa-featured

Thank you for your quick response. That really helped. But I am not familiar with the term you used "path". I have installed build-essentials as you said.  I have created a file with gedit and saved it in desktop as function.cpp. When I start the terminal and type, g++ function.cpp -o outputfile. It gives some error stating, "No such file or directory".

Best Answer
Best Answer
Answered By 0 points N/A #91349

C++ for Ubuntu in Linux

qa-featured

It looks like you are not in the same directory as g++. You said that you saved your file in the desktop. So if you start terminal, you are usually at your home path. Type, cd Desktop. Now use the command, g++ function.cpp -o outputfile.

If there is any error in the code you shall be prompted. If there is no error your code will be compiled to create a executable named "outputfile" specified in the previous command. Just type in the terminal, ./outputfile and you shall see the program run.

Answered By 0 points N/A #91351

C++ for Ubuntu in Linux

qa-featured

Since you are a newbie, I think you should go for a simple IDE, like codeblocks, for a much smoother experience. You have mentioned some of the IDE names in your question. If you find them useful, stick with them. After installing the compiler (build-essentials) the IDE won't give any trouble, I believe.

Answered By 250 points N/A #91352

C++ for Ubuntu in Linux

qa-featured

Thanks for the answer. I am downloading it from the repository.  Is it like Visual Studio?

Answered By 0 points N/A #91353

C++ for Ubuntu in Linux

qa-featured

After installation Go to File> NewFile. In the wizard choose C++ and in the next window, choose the directory where you want to save the code. Then click finish. A editor tab should open, just type your code there and press F9 to build and run at the same time. Just play around with the IDE to get used to it.

Answered By 5 points N/A #91354

C++ for Ubuntu in Linux

qa-featured

Hi Ubuntulover,

Visual Studio unfortunately does not run natively on Linux, particularly Ubuntu. There are however ways to get around your problem and I’ll discuss them here.

Installing it on Ubuntu can be a bit tricky though.

Since it requires wxWidgets.

You can use Debian packages for it.

Install wxWidgets and wxPython on Ubuntu first, before decompressing the tar.bz2 file, which contains the necessary .deb files to run it on Ubuntu.

Note: Your Ubuntu version should be at 10.10 or lower. It does not support 11.04 (Natty Narwhal) yet.

  • Check out Anjuta DevStudio which is a software development studio sporting a considerable number of advanced programming features including Application Wizard, GUI designer, Profiler , Source Editor for C++, Python, Javascript, Version Control, Interactive Debugger , Project Management and many tools like git, valgrind, gdb, profiler, subversion, automake, etc. The interface is simple, dockable and user friendly yet powerful enough as any software in its class out there.
  • Netbeans is an open source Integrated Development application for developers wishing to find alternatives to Visual Studio products. Tools to create a variety of applications ranging from desktop to web and mobile using Java, C++, PHP, Ruby, etc. are present.
  • Monodevelop  which is a cross platform open source IDE supporting C#, Visual Basic.Net, C/C++, and Vala. .NET apps created on Visual Studio can be easily ported to Linux allowing uniform code across all platforms it supports. Tools present on other DevStudio apps exist on Monodevelop like Makefile integration, Packaging/Deployment, Source Control, Unit Testing and others.
  • Although WINE (Windows Emulator) does not support Visual Studio for Windows, there is an alternative called Virtualbox which is a feature laden Virtualization solution by Oracle . Just download Ubuntu .deb packages here  to install the app. When running Virtualbox for the first time, create a new virtual machine by choosing any version of Windows to install. Don’t forget to run the Virtualbox Guest Additions when install has completed. This will ensure mouse integration, and 3D acceleration, among many other enhancements. If you need Visual Studio after, then you don’t need to reboot to Windows,  just run Virtualbox, turn on guest operating system (Windows) and open installed Visual Studio from there.
Answered By 0 points N/A #91355

C++ for Ubuntu in Linux

qa-featured

I think your problem is resolved. Since you said that you found code blocks in the repository, then I guess your distro satisfies the requirement stated by Marcus. Here is a screenshot to help you out with the IDE.

Code blocks in the repository
Answered By 250 points N/A #91356

C++ for Ubuntu in Linux

qa-featured

Thanks all of you. I am now quite at home with programming; sorry to be such a nob. Thanks again.

Related Questions