Home > database >  Linker can't resolve external symbols
Linker can't resolve external symbols

Time:04-02

Everything is indicated properly and yet I'm still getting this error:

LNK2001 unresolved external symbol "public: static bool __cdecl Logger::Logging::Init(void)" (?Init@Logging@Logger@@SA_NXZ)

Logger.h

#include <Windows.h>
#include <stdio.h>
#include <filesystem>
#include <iostream>

class Logger
{
private:
    class Logging
    {
    public:
        static inline bool Init();
    }

public:
    static bool Init(HINSTANCE _hinstDLL);
}

Main.cpp "Place where I want to use the function"

#pragma once
#include "Logger.h"

bool Logger::Init(HINSTANCE _hinstDLL)
{
    FILE* Console;

    AllocConsole();
    freopen_s(&Console, "CONOUT$", "w", stdout);

    if (!Logging::Init())
    {
        Logger::Log("Can't start the initialization!\n");
        return false;
    };
    return true;
}

Logger.cpp "Place where the function is declared"

#pragma once
#include "Cheat.h"

namespace fs = std::filesystem;

inline bool Logger::Logging::Init()
{
    fs::create_directories("C:\\Somewhere");
    fs::path log = "C:\\Somewhere\\log.txt";
    file = CreateFileW(log.wstring().c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    return file != INVALID_HANDLE_VALUE;
}

CodePudding user response:

Removing the inline from declaration and definition of Logging::Init() solved the issue.

Issue solved by @KermittheFrog.

Thanks!

  • Related