2

I have a program, compiled using MinGW on and for windows 10, I want this program to run on other peoples computers, even if they do not have MinGW or any c++ compilers installed.

Normally, this is easy.

I just include the exe file and the dll files for any third party libraries, and it does indeed work ... unless I use one particular c++ standard library, the <filesystem> library from c++ 17, in which case my program can only run on the computer which did the compiling.

For example, this program only prints what file it is currently in to a file.

#include<fstream>
#include<filesystem>

using namespace std;
int main(int argc, char* argv[])
{
    ofstream OUT("location.txt");
    OUT<<filesystem::current_path()<<endl;
    OUT.close();
    return 0;
}

I compile it with mingw32 as such:

g++ stupid_program.cpp -o stupid_program.exe -std=c++17 -O2 -Wall -Wextra -Wpedantic

This does work on the Windows 10 computer which did the compiling, running from terminal (or doubleclicking the .exe) file to creates a file containing the current executing location.

However if I move this .exe file to another windows 10 computer, which did not compile it, doubleclicking the .exe file now causes an error popup to appear, teling me that the entrypoint _ZNKSt10filesystem7_cxx114path5_list13_impl_deletercIEPN"_5_ImpIE could not be found in the DLL-library C:\PATH_TO_PROGRAM\stupid_program.exe.

But the filesystem library does not have any .dll file, because it is part of the standard library. I know the filesystem is a recent addition to the standard ... but I did include the argument -std=c++17 and that should have taken care of that.

So is there any way I can make a program, which does use the filesystem library, work on some other Windows 10 computer than the one which compiled it?

g++ is version 9.2.0 g++.exe (MinGW.org GCC Build-2) 9.2.0

Note, there was an old bug with older MinGW with g++ version 8.xx where the filesystem library could not compile, this is not it, because that bug completely prevented compilation; this cam compile, and run, just only on the compiling computer

Nikolaj
  • 1,137
  • 10
  • 22

3 Answers3

2

Run ntldd -R my_program.exe to get a list of dlls your program depends on.

Look in your compiler's bin directory, and copy any matching DLLs to the same directory as your .exe. Ignore paths reported by NTLDD, and only look at .dll filenames. Ignore any dlls not shipped with the compiler (if you don't use thirdparty libraries).

Then run it again confirm that nothing else is loaded from the compiler's bin directory.

Ship the resulting dlls with your program.


[I'm using] Latest version of mingw32

There are numerous different MinGW distributions, and the one you're using is not the best one. It ships an outdated GCC (9.x vs 12.x), and AFAIK still doesn't support multithreading.

I'd recommend MSYS2 instead.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
1

Did you check that the

libstdc++-6.dll

Is available or the relevant libraries are statically included static linked libs

hsc
  • 356
  • 2
  • 16
0

Try with the much more recent MinGW-w64 instead of old MinGW. You can find a recent standalone version at https://winlibs.com/

MinGW-w64 can target both Windows 32-bit and 64-bit.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • This is the latest version of MinGW. I compile with the 32 bit version, because some of the other libraries I need to use came only as 32 bit – Nikolaj Jul 15 '22 at 17:37
  • @Nikolaj: MinGW-w64 has 32-bit compilers also, which may come as a surprise if you only look at the name. Basically it's the fork that *added* x64 support to MinGW. But **it didn't lose x86 support**. And as Brecht suggested, it's the fork where all new development and maintenance is taking place, the original mingw is effectively abandoned. GCC 12 vs 9. – Ben Voigt Jul 15 '22 at 17:47