I have downloaded Eclipse Juno for C++ from here. I am trying to build a simple hello world program (mostly just to test out using eclipse for C++), but I can't get it to build and run. Here's my code:
#include <iostream>
using namespace std;
int main() {
cout << "hello" << endl;
return 0;
}
The Problems tab shows
make: *** No rule to make target `all'.
I can only assume this is happening because eclipse is not configured to find my compiler (g++
for archlinux), but I can't figure out how to fix it. Ideally I want to be able to program in C++ with Eclipse as easily as you can in Java (i.e. write code, build and run).
Launch Eclipse → Help → Install New Software → In "Work with" field, pull down the drop-down menu and select "Kepler - http://download.eclipse.org/releases/kepler" (or juno for Eclipse 4.2; or helios for Eclipse 3.7). In "Name" box, expand "Programming Language" node ⇒ Check "C/C++ Development Tools" ⇒ "Next" ⇒ ...
An IDE for Embedded C/C++ developers. It includes managed cross build plug-ins (Arm and RISC-V) and debug plug-ins (SEGGER J-Link, OpenOCD, and QEMU), plus a number of templates to create ready to run blinky projects. This package includes a new major release of the Embedded CDT plug-ins (v6.
In Eclipse, go to the "File" menu, then "New", then "C++ Project" if it's there. If not, choose "Project", then find "C/C++" in the list of wizards, click the "+" sign to expand it, and choose "C++ Project". A dialog box will ask whether to open the C/C++ perspective. Answer "yes", and remember this decision.
A Makefile is a file that serves as a "map" to build a project from the command line (or using an IDE like in your case). It is good practice to use a Makefile to compile complex projects composed of many files, since the compilation can be done with or without the IDE (Eclipse in your case). To compile your project outside Eclipse, just type "make" from the command line.
In your case, somehow you have selected the option to compile using a makefile (this option in my opinion is the best).
To solve your problem from this point (without having to re-create the project), just add a blank file to your project:
File-> New-> Other
Expand "General" and select "File"
Name it "Makefile" (it is important to put this name) (I assume that your source code is stored in a file named "main.cpp" and that your executable will be called "hello") (I assume also that the g++ is installed on your system, as some Linux distributions have gcc preinstalled only)
Edit the file "Makefile" (in the same Eclipse if you like) with the following: (it is important to respect the tabs!)
all: main.o
g++ -o hello main.o
main.o: main.cpp
g++ -c main.cpp
clean:
rm *.o
Now, when you compile your project, you should see something like this: (in the "console" tab)
make all
g++ -c main.cpp
g++ -o hello main.o
This is the simplest Makefile you can create for your project. There is plenty of help available on the web about the syntax of the Makefile for much more complex builds.
follow this: create new c++ project. Than in project type chose Executable - > Hello world.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With