0

I'm trying to figure out how to get a makefile working for my .cpp file

Here is the code for main.cpp:

#include <iostream>

using namespace std;

int main() {
    cout << "hello world!" << endl;
   return 0;
}

Here is my code for the make file: all: main.exe

main.exe: main.o
     g++ -o main.exe main.o

main.o: main.cpp
     g++ -c main.cpp

When I enter the command "make"

I get this: enter image description here

But when I run main.exe I get this: enter image description here

And if I run main.exe as administrator I get this: enter image description here

1
  • I am running this on Windows 64-bit though. Commented Oct 9, 2014 at 3:35

1 Answer 1

2

Your makefile looks fine. However, it looks like you're compiling on a Linux machine through Putty. If that's true, there's your problem. Running g++ on Linux will target Linux. Simply appending .exe to your file name will not make it compatible with Windows.

There are tutorials out there for compiling for Windows on Linux, or you can install the proper compilers on your Windows machine, or simply run the compiled program inside a Linux environment.

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

2 Comments

That makes sense, thank you. Could I run the make file through cmd?
make isn't part of Windows without installing it. I've never actually done that, but it looks like this link might be a good place to start. You'd probably need to install g++ or cl to compile code. I would imagine there are some other answers on this site about doing exactly that. However, if you're really just running something that small, it's probably easier just to execute it through Putty immediately after compiling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.