0
  1. main.cpp
#include <iostream>
#include "log.hpp"

int main()
{
    InitLog();
    Log("Hello World");
    std::cin.get();
}
  1. Log.cpp
#include <iostream>
#include "log.hpp"

void InitLog()
{
    Log("Initialize Log");
}

void Log(const char *message)
{
    std::cout << message << std::endl;
}
  1. log.hpp
#pragma once

void Log(const char *message);
void InitLog();

The errors are:

  1. Log.cpp - undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status

  2. main.cpp - c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\91813\AppData\Local\Temp\cckelbDG.o:main.cpp:(.text+0xe): undefined reference to InitLog()' c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\91813\AppData\Local\Temp\cckelbDG.o:main.cpp:(.text+0x1d): undefined reference to Log(char const*)' collect2.exe: error: ld returned 1 exit status

  • You have two very different problems, actually. The first is that your project is set up as a native Windows project, not a console project. The second problem is that you don't build with both source files. Please [edit] your question to include your project settings and configuration, as well as telling us the environment you use to configure and build your project, and how you build your project. – Some programmer dude Jul 08 '22 at 07:40
  • Also please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And learn how to [edit] your questions to improve them. – Some programmer dude Jul 08 '22 at 07:41

0 Answers0