Cześć.
Struktura plików wygląda u mnie tak:
E:.
│ main.cpp
│ ...
│
|
├───config_utils
│ config_utils.cpp
│ config_utils.h
│
└───others
utils.cpp
utils.h
pliki .h wyglądają tak:
#ifndef PTS_UTILS_H
#define PTS_UTILS_H
#include <string>
#include <optional>
#include <string_view>
std::optional<std::string> getEnvVar(std::string_view name);
#endif
#ifndef PTS_CONFIG_UTILS_H
#define PTS_CONFIG_UTILS_H
#include <filesystem>
#include <tuple>
namespace fs = std::filesystem;
namespace cfg_utils{
enum class CFG_GATHER_WAY{
LOCAL,
ENVVAR,
USER,
NOTHING
};
enum class CFG_CREATION_ERR{
FILE_ERR,
ENV_VAR_ERR,
NO_ERR
};
std::tuple<fs::path, CFG_GATHER_WAY> findConfigFile();
std::pair<fs::path, CFG_CREATION_ERR> createConfigFile();
}
#endif
wszystkie definicje i deklaracje się zgadzają, a kompilując w ten sposób:
g++ (warningi) -std=c++1z others/utils.cpp -c -o utils.o
g++ (warningi) -std=c++1z config_utils/config_utils.cpp -c -o config_utils.o
g++ (warninig) -std=c++1z utils.o config_utils.o main.cpp
dostaję takie błędy linkera:
C:\Users\In5ert\AppData\Local\Temp\cc2UuDP1.o:main.cpp:(.text+0x31): undefined reference to `cfg_utils::findConfigFile[abi:cxx11]()'
C:\Users\In5ert\AppData\Local\Temp\cc2UuDP1.o:main.cpp:(.text+0xbc): undefined reference to `cfg_utils::createConfigFile[abi:cxx11]()'
collect2.exe: error: ld returned 1 exit status