I build a dll with functions to be used in an exe which I currently mock. Both bins build correctly but the problem emerges when there's
std::filesystem::path
variable declared in imported function:
dll mylib.h
namespace mylib
{
MYLIB_EXPORT void foo(const std::string& bar) noexcept;
}
dll mylib.cpp
#include <filesystem>
#include <iostream>
namespace mylib
{
void foo(const std::string& bar) noexcept
{
std::filesystem::path pathToFile(bar); // problematic line
std::cout << bar << std::endl;
}
}
mock main.cpp
#include "mylib.h"
int main(int argc, const char** argv)
{
std::cout << "MockEntry" << std::endl;
std::string path{"foo"};
mylib::foo(path);
std::cout << "MockExit" << std::endl;
}
The dll is linked properly but running mock.exe produces no output in terminal, only under gdb the result is:
(gdb) run
Starting program: .../mock.exe
[New Thread 30948.0x6490]
[New Thread 30948.0x7a84]
[New Thread 30948.0x11d4]
[Thread 30948.0x64b4 exited with code 3221225785]
[Thread 30948.0x11d4 exited with code 3221225785]
[Thread 30948.0x7a84 exited with code 3221225785]
During startup program exited with code 0xc0000139.
When I comment out the line:
// std::filesystem::path pathToFile(bar); problematic line
everything runs as expected and the output is:
MockEntry
foo
MockExit
The tools I use are CMake, ninja, gcc 13.2 (MinGW). C++20 enabled in CMake.
I have tried to build minimalistic executable using filesystem with
#include <filesystem>
#include <iostream>
#include <string>
int main(int argc, const char** argv)
{
std::cout << "foo" << std::endl;
std::filesystem::path{"bar.txt"};
std::cout << "foo2" << std::endl;
}
and minimalistic CMake:
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER "C:/ProgramData/mingw64/mingw64/bin/g++.exe")
project(blank
LANGUAGES CXX)
set (NAME blank)
set(SOURCES
main.cpp)
add_executable(${NAME} ${SOURCES})
and the result is the same - crash.
Help will be much appreciated as I can't sort out the problem.