6

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).

4
  • 2
    You created a new C++ project, correct? Not a makefile project with existing code? If you accidentally selected the latter, that could be the problem. I don't see anything in the wiki specific to this, so that might be the problem. The reason I ask about the type of project is because normally, if Eclipse can't find g++, it will give an error similar to Cannot run program "g++", which means exactly what you'd think (also +1 for being another Arch user). Commented Jul 23, 2012 at 19:56
  • 2
    That is explicitly a make error. You should have configured the project to build using a Makefile. You need to fill your Makefile, below the "all" target, the commands to build the project. Commented Jul 23, 2012 at 19:59
  • @Spidey Phrased it better than I did in reference to the makefiles, but since he's only looking to compile a simple C++ program for the time being, I think the problem may still be that he selected a makefile project in the first place. Commented Jul 23, 2012 at 20:02
  • @RicardoAltamirano I did not create a Makefile with existing code, I clicked New > C++ Project. I really don't know anything about makefiles (though I know I probably need to learn). since the code is so simple though, I think I should be able to just use g++ directly through eclipse instead of having to create one Commented Jul 23, 2012 at 20:57

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

follow this: create new c++ project. Than in project type chose Executable - > Hello world.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.