4

I have a program

#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
    cout<<"Hello World!! This Program Is made in win32 API\n";
    return 0;
}

but when I compile this program

x86_64-w64-mingw32-g++ Hello.cpp -o hello64.exe

and run it

wine64 hello64.exe

I get 2 errors

0009:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\garvit\\C++\\hello64.exe") not found
0009:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\garvit\\C++\\hello64.exe" failed, status c0000135

I am using Ubuntu 20.04, and i am new to Linux.

Garvit Joshi
  • 63
  • 2
  • 7

2 Answers2

2

You need to copy this libstdc++-6.dll from your mingw installation (should be in /usr/lib/gcc/x86-w64-mingw32/9.3-win32/) to the same directory as your exe file. I expect you will get a similar message about libgcc_s_sjlj-1.dll, which you also need to copy.

I tested this with 32-bit and on a windows VM, but I hope that that will not make a difference.

Siep
  • 121
0

You are getting errors because Wine doesn't know where those libraries are available. You have two options:

  • Place all required libraries in the same directory
  • Statically link with required libraries

If you don't have licensing issues (e.g libstdc++ uses LGPL, to link with that library, you need to license your program under LGPL if you distribute it), you should statically link. For a hello world program, the compilation command will be like this:

x86_64-w64-mingw32-g++ hello.cpp -static-libstdc++ -static-libgcc -o hello

Another option is to place all libraries at the same directory. So just copy those files from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/ or /usr/lib/gcc/x86-w64-mingw32/9.3-win32/ and your program should run well.