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
  • 65
  • 2
  • 7
  • You can set `WINEPATH` to point to the folder with the DLLs. For example: `WINEPATH=/usr/local/x86_64-w64-mingw32/bin/;/usr/lib/gcc/x86_64-w64-mingw32/10-win32/` – Daniel Stevens Nov 30 '21 at 02:04

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
  • 111
  • 7
  • After Importing I got the same error for ```libgcc_s_seh-1.dll```, after importing it to same directory the program is working fine. Also is there any way i can import these files globally rather then omporting it in all my projects. – Garvit Joshi May 22 '20 at 06:35
  • If you keep the dlls with the exe then you know that they come from the same compiler and should be compatible. If you put the dlls on the searchpath then you do not know which programs will try to use them. But I do not know for a fact that this is really a concern. – Siep May 22 '20 at 19:16
  • ok, if i have any update on this issue i will let you know – Garvit Joshi May 22 '20 at 19:35
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.

Akib Azmain Turja
  • 1,022
  • 1
  • 12
  • 28