【问题标题】:Error: LINK: fatal error LNK1561: entry point must be defined c++错误:链接:致命错误 LNK1561:入口点必须定义 C++
【发布时间】:2016-12-10 18:04:13
【问题描述】:

尝试编译代码时出现以下错误:error LNK1561: entry point must be defined.

背景:我正在尝试运行 Win32 CONSOLE 应用程序并使用 Google Tests 框架。

我有我的主要功能设置,我已经检查了我的Linker 设置为Console (/SUBSYSTEM:CONSOLE) 在我见过的许多问题中的其他一些建议。我不确定它为什么不喜欢我的 main 函数,因为它被定义为入口点。

这是我的代码:

bob.h

#ifndef BOB_BOB_H
#define BOB_BOB_H

#include <string>
using namespace std;

namespace bob {
    string hey(const string&);
}

#endif

bob.cpp

#include "bob.h"

using namespace std;

namespace bob {

string hey(const string& theString) 
{
    return "Whatever."
}

}

bob_tests.cpp

// bob_tests.cpp : Defines the entry point for the console application
//

#include "bob.h"
#include <gtest/gtest.h>

int main(int argc, char** argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

TEST(Bob, stating_something)
{
    EXPECT_STREQ("Whatever." bob::hey("Tom-ay-to, tom-aaaah-to."));
}

【问题讨论】:

    标签: c++ googletest


    【解决方案1】:

    进一步详细说明 Mihaylov 的帖子。

    在 VS 中,更新项目的属性,确保您的项目 No Entry Point 链接器属性设置为 NO

    项目属性页/链接器/高级/无入口点 = 无

    接下来更新链接器子系统属性

    项目属性页/链接器/系统/子系统=控制台(/SUBSYSTEM:CONSOLE)

    【讨论】:

      【解决方案2】:

      您必须设置入口点。我看到你写了“Console (/SubSystem:CONSOLE)”所以我认为你在 Visual Studio 所以你需要做的是去 Linker->Advanced->(确保“No Entry”设置为“ No")->Entry 必须设置为“main”。

      【讨论】:

      • “No Entry”设置为 No。我应该更改它吗?
      • Linker->Advanced->Entry = main, Linker->Advanced->No Entry = No
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多