Linux mingw32 sfml cross compile for windows - missing dll files - c++

I am compiling my C++ project in the following way:
/usr/bin/i686-w64-mingw32-g++ -g -std=c++0x -Wall -I /home/bluszcz/dev/win64/SFML-2.1/include -L /home/bluszcz/dev/win64/SFML-2.1/lib -static-libgcc -static-libstdc++ -static -O4 -c src/game.cpp -o src/game.a -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
However, when I try to run my exe file I am getting an error about missing DLL files:
bluszcz#zendo ~/dev/win32/builds/magicwizard $ wine mw.exe
err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-system-2.dll") not found
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libwinpthread-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-system-2.dll") not found
err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found
err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libwinpthread-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found
I have compiled using static options - so why it asks for libgcc_s_dw2-1.dll for example?
Also, I copied some files there, but the application still doesn't see them.
bluszcz#zendo ~/dev/win32/builds/magicwizard $ ls *dll
libsndfile-1.dll sfml-audio-2.dll sfml-graphics-d-2.dll sfml-system-2.dll sfml-window-d-2.dll
libstdc++-6.dll sfml-audio-d-2.dll sfml-network-2.dll sfml-system-d-2.dll
openal32.dll sfml-graphics-2.dll sfml-network-d-2.dll sfml-window-2.dll
bluszcz#zendo ~/dev/win32/builds/magicwizard $
And some files, like libgcc_s_dw2-1.dll, don't exist on my file system at all...
To summarize:
Why does my application not see the missing files?
How to compile in static way with mingw32?
How to get the missing files?
I use this version of sfml library to compile it: http://www.sfml-dev.org/download/sfml/2.1/SFML-2.1-windows-gcc-4.7-mingw-32bits.zip

The missing dll's can simply be added to your WINEPATH before running your program with wine, i.e.
export WINEPATH="/usr/x86_64-w64-mingw32/lib;/usr/lib/gcc/x86_64-w64-mingw32/7.3-posix"
!Note, your paths might be slightly different depending on the mingw version you are using.

Answering only the last of the three question:
About the standards libraries, it worked for me to copy them from the mingw folder:
cp /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libstdc++-6.dll ./
However, when I copied from the wrong directory according to my build (e.g. /usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/libstdc++-6.dll) I still had the same error while the file with the exact same name was here.

On my Fedora 26 after installing mingw64-gcc and mingw64-gcc-g++:
[leo#pc]$ locate libgcc_s_seh-1.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll
[leo#pc]$ locate libstdc++-6.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll
[leo#pc]$
If I copy dll's and run wine with generated a.out.exe it works.

Probably your application isn't seeing the files because it's configured like that, and you don't need to add tags like -static to the command.
For compiling static libraries, you must add -s, like -lsfml-window-s -lsfml-system-s
libgcc_s_dw2-1.dll is just inside bin folder, on latest MinGW releases.
If there are missing dlls, there's probably a version incompatibility.

Related

Wine cannot load DLLs even though the directory is added to PATH

I am trying to cross-compile Windows software on Linux using mingw32-w64 and running it with wine. However wine cannot load the libstdc++-6.dll library file. I searched online and found out that you have to put the directory that contains the DLL file into the path registry. In my case, that directory is Z:\bin\i686-w64-mingw32\bin.
Then I tried to run the compiled file by using wine executable.exe and the output is:
0100:err:module:import_dll Loading library libstdc++-6.dll (which is needed by L"Z:\\home\\sunnymonster\\dev\\c++\\opengl-tests\\cmake-build-debug\\opengl_tests.exe") failed (error c000007b).
0100:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\sunnymonster\\dev\\c++\\opengl-tests\\cmake-build-debug\\opengl_tests.exe" failed, status c0000135
I have verified that I am using the correct wine prefix.
Additional information:
Linux distro: Manjaro Linux 21.2.5
Linux kernel: 5.16.14-1
There're multiple approaches. First, let's formalize the problem:
$ cat test.cpp
#include <iostream>
int main() { std::cout << "hello" << std::endl; }
$ i686-w64-mingw32-g++ test.cpp -o a && WINEDEBUG=-all,err+module wine ./a.exe
0024:err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\tmp\\a.exe") not found
0024:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\tmp\\a.exe") not found
0024:err:module:LdrInitializeThunk Importing dlls for L"Z:\\tmp\\a.exe" failed, status c0000135
Solutions:
Link the core libraries statically:
$ i686-w64-mingw32-g++ test.cpp -o a -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
$ WINEDEBUG=-all,err+module wine ./a.exe
hello
Use WINEPATH env. variable to tell wine the additional paths to load dlls from. In the example I pass it the location with mingw dlls that wine complains about. It may be different on your system, you might find it by asking package manager to list files in mingw-g++/gcc packages (whatever it's called on your system). Multiple paths should be separated by semicolon.
$ i686-w64-mingw32-g++ test.cpp -o a
$ WINEDEBUG=-all,err+module WINEPATH=/usr/i686-w64-mingw32/sys-root/mingw/bin/ wine ./a.exe
hello
Install a Windows version of MinGW, and then use it to compile the app. However, from what I remember, if you want to distribute the executable produced, you still need to either statically link against MinGW libs, or provide them together with the binary. So the only difference to point 1 is that the binary should work under your WINEPREFIX with no modifications.
Using wineg++. I mention it solely for completeness, I think it's the least useful solution. It produces a Linux file, which in itself might be okay, one could use that for debugging. However, in my tests, I didn't manage to makewineg++ link against a dll, even though mingw links to the same dll without a problem. It seems to link against .so files instead, even though the application you build with it can load .dll files dynamically. Odd utility.
$ wineg++ test.cpp -o a
$ WINEDEBUG=-all,err+module wine ./a.exe
hello

Link libraries to linux biinary file in c++

I'm compiling a c++ program using g++ and i am using two libraries called libsdl2-dev and libsdl2-image-dev
I installed both these libraries in my ubuntu machine with the commands
apt install libsdl2-dev libsdl2-image-dev and when I compile the program everything works fine. Then I copied these libraries from /usr/lib/x86_64-linux-gnu/ to my working dir with the binary file to be able to give this folder to someone else.
The problem comes when the user that hasn't installed these libraries tries to open my program by writing ./main (the binary file). Since he hasn't installed these libraries he would get an error like "can't open shared object: no such file or directory".
This happens because the binary file looks for these libraries in /usr/lib etc...
What i need
I need that my binary file looks for these libraries in the same folder,and not in /usr/lib/x86 etc.., from what I read I have to do something like rpath
The IDE used is Sublime Text and the syntax used to compile all my files is this:
g++ -c src/*.cpp -std=c++14 -m64 -g -Wall -I include && g++ *.o -o bin/debug/main -lSDL2main -lSDL2 -lSDL2_image && ./bin/debug/main`
Structure of folders
I got the project dir with and inside that i got 4 more directories, each one called: bin (with the debug subdirectory, where we got the final compile), include (with hpp files), res (with all textures), and src with all cpp files to compile, the other files are project files and .o files
I'm using Ubuntu 20.04-2 LTS and the same is for the other user's PC
Thanks in advance for any help!
That's because the dynamic linker loading runtime dependencies looks for them in some specified locations, which are "by default" your system library directories (where those libraries got installed by apt).
The other user should ideally install those libraries too (which could be done "automatically" if you build a .deb package with proper dependencies)
Otherwise you would have to change the runpath of your program by adding -Wl,-rpath='$ORIGIN', which makes the dynamic linker look for dependencies just where the binary is located.
$ORIGIN here is a special variable meaning "this executable" which is what you wanted to achieve.
see rpath
and A description of RPATH $ORIGIN
I found a way to resolve!
I used the program patchelf to add an rpath to my directory (linked to the binary file) now everything works
use ldd ./bin/debug/main to check the library
export LD_LIBRARY_PATH =$LD_LIBRARY_PATH:"your library path"
run the program,if this is not work. use patchelf to change the rpath to you r library

Weird things with libCurl and OpenSSL

It's me again. I just can't understand, why it goes that way!
I downloaded compiled static libs of OpenSSL, from here, this link is on the official cUrl site in Download page. I downloaded Zlib and compiled them, then I compiled libcurl with
mingw32-make mingw32-ssl-zlib
I changed in all makefile.m32 pathes to the Zlib and OpenSSL files. All went fine, I recieved libcurl.a and libcurldll.a. I added into lib folder of my project libcurl.a and libeay32.a, libssleay32.a and libz.a.
I built project - it says that everything is fine. I run - and it just terminated. I'm using MinGW and Eclipse.
It is compiled with this:
g++ -DCURL_STATICLIB -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o ..\src\main.cpp
g++ -L..\lib -oYTUploader.exe src\main.o -lcurl -lws2_32 -lwldap32 -leay32 -lssleay32 -lz
I run DependencyWalker, and it says that it's missing ieshims.dll, libeay32.dll and ssleay32.dll. But WHY? Why it want OpenSSL dll, I'm using static linking! I built static libCurl library, with static libs of OpenSSL. About ieshims.dll I also can't get why it needs it!
Help, please, I have no idea what is wrong! I compiled cUrl according to the instruction, everything should be fine..
The openssl-libs you link against seem to be import-libraries. That means they only contain the information your code needs to call functions and then load and call the corresponding functions from the dll.
So the problem is: although you link to static libs, the libs then load and use dynamic dlls. They are no "real" static libs.
One solution is getting other libs (or compile them yourself), or even easier: you just copy the dlls into the directory where your .exe resides and you should be fine.
Use the configure script to tell ld where openssl has installed the files. the defaults are as follows:
tar -zxf curl-7.33.0.tar.gz
cd curl-7.33.0
./configure --prefix=/opt/curlssl --with-ssl=/usr/local/ssl --enable-http --enable-ftp LDFLAGS=-L/usr/local/ssl/lib CPPFLAGS=-I/usr/local/ssl/include
make
make install

Symbol lookup error problem in QT project

I am trying to add a new library to the Qt plugins folder.
That plugin is located here:
http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtjp2imageformat
It says that it requires jasper to build, so I downloaded jasper, and built it, generating a libjasper.a in my jasper/lib folder (which is in my home dir, not in /usr or anything)
So i built out qtjp2imageformat using the jasper include files, and linking against that libjasper.a file
here are the relevant lines from the makefile:
INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. -I/usr/lib64/qt4/include/QtCore -I/usr/lib64/qt4/include/QtGui -I/usr/lib64/qt4/include -I../src -I. -I/home/dcole/software/jasper-1.900.1/include
LIBS = $(SUBLIBS) -L/usr/lib64/qt4/lib64 -L/home/dcole/software/jasper-1.900.1/lib -ljasper -lQtGui -L/usr/lib64/mysql -L/usr/lib64/qt4/lib64 -L/usr/X11R6/lib64 -lQtCore -lpthread
I then put the generated libqtjp2.so in the QT Plugins/imageformats folder, and now when my code runs, and gets to the part where it's going to read a jpeg2000, I get the following: symbol lookup error: /usr/lib64/qt4/plugins/imageformats/libqtjp2.so: undefined symbol: jas_init
So I think jas_init comes from jasper - how come my QT project can't see that? Do I need to also make MY project link against libjasper.a, or have I linked the library wrong when I built libqtjp2?
Thanks
You didn't say which distro you are using, but the simplest would be to install the jasper package and link your application to it's library.
by the way, did you build static library (.a) or dynamic (.so)? Try building a dynamic library

Boost installation and library paths

I have been using Boost (the header only library part) for sometime now. I recently started on a project that required the compiled libraries (filesystem etc).
I followed the instructions given in the documentation, and was under the impression that the libraries to installed (directly) in the usr/local folder. After a lot of trial and error, I found that the correct (*.a) files to use were in:
/usr/local/boost_1_45_0/stage/lib/
Is this the correct folder to use for linking the boost built shlibs (shared libraries)?
An example for linking regex static(*.a) lib:
g++ -I /usr/local/boost_1_45_0 -c your_regex_prog
g++ -static -o static_regex your_regex_prog.o -lboost_regex