Syzygy
Syzygy

Reputation: 31

Error message in codeblocks: Undefined reference to 'WinMain@16'

I want to run the following code in Codeblocks 20.03, but I get the error message: Undefined reference to 'WinMain@16'.

Code:


std::string countSheep(int number) 
{
  std::string res;
  std::string s = " sheep...";

  for (int i = 1; i <= number; i++) {
    res += std::to_string(i) + s;
  }

  return res;
}

The initial problem was, that I got the error message: to_string’ is not a member of ‘std After that I have updated my GCC compiler to 9.2.0. But now, I keep getting that winmain error message.

Do you have any idea, what to do?

Upvotes: 0

Views: 673

Answers (1)

Alex Susanu
Alex Susanu

Reputation: 161

Have a look at this: C++ undefined reference to WinMain@16 (Code::Blocks)

and this: Undefined reference to WinMain@16 - Codeblocks

also regarding your code, maybe some of the more experienced c++ here might tell me I am wrong. But your function countSheep you are not returning anything, you are trying to print res I presume ? so you are not returning a string that you can use later in a var, you are only printing out.

if that's the case and as I mentioned earlier, others more experienced can tell me I am wrong about this, try this: `

#include <iostream>
#include <string>

void countSheep(int number);

int main()
{
   countSheep(3);
}
void countSheep(int number) 
{
        std::string res;
        std::string s = " sheep...";

          for (int i = 1; i <= number; i++) 
          {
                res += std::to_string(i) + s;
                std::cout << res << std::endl;
            }
}

Upvotes: 0

Related Questions