如何为.cpp文件创建工作makefile

时间:2014-10-09 03:25:58

标签: c++ makefile

我试图找出如何让makefile运行我的.cpp文件

以下是main.cpp的代码:

#include <iostream>

using namespace std;

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

这是我的make文件的代码:     all:main.exe

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

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

当我输入命令&#34; make&#34;

我明白了:enter image description here

但是当我运行main.exe时,我得到了这个: enter image description here

如果我以管理员身份运行main.exe,我会得到: enter image description here

1 个答案:

答案 0 :(得分:2)

你的makefile看起来很好。但是,看起来你正在通过Putty在Linux机器上进行编译。如果这是真的,那就是你的问题。在Linux上运行g ++将以Linux为目标。只需将.exe附加到您的文件名就不会使其与Windows兼容。

有一些教程可以在Linux上编译Windows,或者你可以在Windows机器上安装适当的编译器,或者只是在Linux环境中运行已编译的程序。

相关问题