1

I am getting the following error when trying to compile my code: error LNK1561: entry point must be defined.

Background: I am trying to run a Win32 CONSOLE application and use the Google Tests framework.

I have my main function setup and I've already checked that my Linker is set to Console (/SUBSYSTEM:CONSOLE) per some other suggestions in many questions I've seen. I'm not sure why it doesn't like my main function, because that is defined as the entry point.

Here is my code:

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."));
}
WitchKing17
  • 185
  • 3
  • 21

2 Answers2

4

to elaborate further on Mihaylov's post.

In VS, update the project's properties make sure your project No Entry Point linker property is set to NO.

Project Property Page/Linker/Advanced/No Entry Point = No

Entry Point

Next update the linker subsystem property

Project Property Page/Linker/System/SubSystem = Console(/SUBSYSTEM:CONSOLE)

Project Property Page

nmctwisp
  • 185
  • 1
  • 6
1

You have to set the entry point. I saw that you written "Console (/SubSystem:CONSOLE)" so I think you are on Visual Studio so what you need to do is to go to Linker->Advanced->(make sure that "No Entry" is set to "No")->Entry must be set to "main".

K. Mihaylov
  • 103
  • 2
  • 10