Creating makefile for a C++ program to run with g++

8.7k Views Asked by At

I have a sample program in a file called "helloworld.cpp":

#include <iostream>

using namespace std;
int main(int argc, char** argv)
{  
  cout<<"Hello World!";
  return 0;
}

I am trying to write a makefile for this as follows:

all: g++ helloworld.cpp -o helloworld

Right now I am on windows and couldn't test this. However, when I submit this to one of the site (www.gild.com) it is telling me that submission has failed due to build error. Can somebody point out what is wrong here?

2

There are 2 best solutions below

1
On BEST ANSWER

You have the action to be run on the part of the line where the dependency goes. Try this:

all: 
        g++ helloworld.cpp -o helloworld

Make sure that's one tab, not spaces in any quantity.

0
On

If your solution only contains one class no makefile is required

http://www.gild.com/challenges/details/code_submission_guidelines?keyword=missile

edit: Also you will want to make sure your folders are organized correctly. This is a good place to start http://community.gild.com/gild/topics/help_me_to_submit_helloworld_solution_in_java