C++ ошибки при сборке | Cmake

Так как кода сравнительно мало - позволю себе выложить весь код.

main.cpp

#include <iostream>


int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

source/inputManager.cpp

#include <string>
#include <filesystem>
#include "methods.cpp"


using std::string;
using std::cout;
using namespace methods;

string execute() {
    const string default_path = "./numbers.txt";
    string data;
    if (std::filesystem::exists(default_path)) {
        if (answer("Default file " + default_path + "found.\nUse it?")) {

            console_clear();
            return data;
        } else {
            if (answer("Y - generate the \"numbers.txt\"\nN - use custom path")) {

            }
        }

    }
    return "";
}  

source/methods.cpp

#define CIN_FLUSH cin.ignore(INT_MAX)
#define UPPER_LIMIT 9999999
#define LOWER_LIMIT 1000000

#include <string>
#include <iostream>
#include <fstream>
#include <random>
#include <vector>
#include <algorithm>
#include <ctime>
#include <sstream>

using std::string;
using std::cout;
using std::cin;
using std::ofstream;
using std::vector;
using std::ifstream;
using std::stringstream;

namespace methods {
    bool answer(const string &message) {
        cout << message << " (y/n)";
        char ans;
        do {
            cout << "\n> ";
            cin >> ans;
            CIN_FLUSH;
        } while (tolower(ans) != 'y' && tolower(ans) != 'n');

        return ans == 'y';
    }

    void console_clear() {
#ifdef WIN32
        system("cls");
#else
        system("clear");
#endif
    }

    int *generate_file() {
        vector<int> _temp;
        for (int i = LOWER_LIMIT; i < UPPER_LIMIT; ++i)
            _temp.push_back(i);

        shuffle(_temp.begin(), _temp.end(), std::default_random_engine(time(nullptr)));

        ofstream fout("numbers.txt");

        for (const auto &e : _temp) fout << e << "\n";
        cout << "File generated\n";

        int *array = nullptr;
        std::copy(_temp.begin(), _temp.end(), array);

        return array;

    }

    int *read_file(const string &path){
        int *result = new int[0];

        ifstream fin(path);
        stringstream buffer;
        buffer << fin.rdbuf();
        fin.close();

        return result;
    }

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(untitled)

set(CMAKE_CXX_STANDARD 20)

add_executable(untitled main.cpp source/inputManager.cpp source/methods.cpp)

Ошибки при сборке

"C:\Program Files\JetBrains\CLion 2020.1.2\bin\cmake\win\bin\cmake.exe" --build C:\Users\icyftl\CLionProjects\untitled\cmake-build-debug --target untitled
Scanning dependencies of target untitled
[ 25%] Building CXX object CMakeFiles/untitled.dir/source/inputManager.cpp.obj
inputManager.cpp
[ 50%] Linking CXX executable untitled.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\untitled.dir\objects1.rsp /out:untitled.exe /implib:untitled.lib /pdb:C:\Users\icyftl\CLionProjects\untitled\cmake-build-debug\untitled.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\untitled.dir/intermediate.manifest CMakeFiles\untitled.dir/manifest.res" failed (exit code 1169) with the following output:
methods.cpp.obj : error LNK2005: "bool __cdecl answer(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?answer@@YA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 㦥 ®ЇаҐ¤Ґ«Ґ­ ў inputManager.cpp.obj
methods.cpp.obj : error LNK2005: "void __cdecl console_clear(void)" (?console_clear@@YAXXZ) 㦥 ®ЇаҐ¤Ґ«Ґ­ ў inputManager.cpp.obj
methods.cpp.obj : error LNK2005: "int * __cdecl generate_file(void)" (?generate_file@@YAPEAHXZ) 㦥 ®ЇаҐ¤Ґ«Ґ­ ў inputManager.cpp.obj
methods.cpp.obj : error LNK2005: "int * __cdecl read_file(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?read_file@@YAPEAHAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 㦥 ®ЇаҐ¤Ґ«Ґ­ ў inputManager.cpp.obj
untitled.exe : fatal error LNK1169: ®Ў­ а㦥­ ¬­®Ј®Єа в­® ®ЇаҐ¤Ґ«Ґ­­л© бЁ¬ў®« - ®¤Ё­ Ё«Ё Ў®«ҐҐ
NMAKE : fatal error U1077: "C:\Program Files\JetBrains\CLion 2020.1.2\bin\cmake\win\bin\cmake.exe" : возвращенный код "0xffffffff"
Stop.
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe" : возвращенный код "0x2"
Stop.
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe" : возвращенный код "0x2"
Stop.
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe" : возвращенный код "0x2"
Stop.

Не знаю как правильно искать ошибки в таких случаях.
Уж больно общую инфу возвращает cmake.

P.S.: Очевидно, проект еще не дописан и как следствие - в некоторых функциях, со смысловой точки зрения, может происходить ахинея.


Ответы (0 шт):