【问题标题】:C++ LNK1120 Fatal Error: 1 unresolved externalsC++ LNK1120 致命错误:1 个未解决的外部
【发布时间】:2012-02-27 00:10:37
【问题描述】:

我正在尝试使用 MS Visual Studio Professional 2010 编译此代码,它给了我一个构建错误 LNK1120 Fatal Error: 1 unresolved externals。 这是代码...

// Program Typos prints three integer numbers, sums the numbers, calculates
// the average, and prints the sum and the average of the three numbers.

#include <iostream>
#include <iomanip>
using namespace std;

const int ONE = 5;
const int TWO = 6;
const int THREE = 7;

int main ()
{
    int sum;
    float average;


    cout  << fixed  << showpoint;

    cout << setw(5) << ONE  << TWO  << THREE << endl;
    sum = ONE + TWO + THREE;
    average = sum / 3;
    cout  << " The sum is "  << sum  << " and the average is " \
      << average  <<endl;
    return 0;
}

【问题讨论】:

  • 什么是未解决的外部?这编译得很好。
  • 你的错误在别处。你没有充分准备这个问题。
  • 在您的问题中,您将平均值计算为整数。在这种特殊情况下,这恰好可以解决,但这只是巧合。

标签: c++ visual-c++


【解决方案1】:

唯一的可能是缺少WinMain(或其变体)。要解决转到项目设置,链接器 -> 系统,然后选择/SUBSYSTEM:CONSOLE

这不是问题,请粘贴整个错误消息。

【讨论】:

    猜你喜欢
    • 2011-11-16
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2013-07-10
    • 2015-01-11
    相关资源
    最近更新 更多