【问题标题】:MinGW .h compiled files not working: The version of this file is not compatible with the version of Windows you're runningMinGW .h 编译文件不起作用:此文件的版本与您正在运行的 Windows 版本不兼容
【发布时间】:2014-01-25 03:07:18
【问题描述】:

如果我编译的文件是 .h 类型,我的 .exe 文件将不会运行。

这是我放的 C++ 代码:

#include <iostream>
using namespace std;

int main(){
    int var = 0, sum = 0;
    while (std::cin >> var){
        sum += var;
    }
    std::cout << "sum " << sum << std::endl;
    return 0;
}

我使用MinGW进行编译,我将文件命名为CTesting.h并编译它,运行exe时出现以下错误:

此文件的版本与 Windows 的版本不兼容 你在跑。检查计算机的系统信息以查看 无论您需要 x86(32 位)还是 x64(64 位)版本的 程序,然后联系软件发行商。

当我将源填充重命名为 .cpp 类型时,我没有收到此错误。我的理解是 C++ 使用了 .h 和 .cpp 文件,这是不正确的吗?还是我做错了什么/忘记了什么?

【问题讨论】:

标签: c++ windows mingw


【解决方案1】:

你不能在这里使用.h 扩展名! MinGW 会将 CTesting.h 识别为 header 文件。您必须使用 source 文件扩展名(例如,.cpp 用于 C++ 或 .c 用于 C),这样 GCC 才能正确确定它。

有关所有文件扩展名的列表,请参阅here,有关头文件的 GCC 手册请参阅here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 2018-10-07
    • 2015-08-06
    • 1970-01-01
    相关资源
    最近更新 更多