Missing libgcc_s_dw2-1.dll - c

I have a Windows 7 64bit system with the latest MinGW (32bit) installed along with the Qt 5.5 SDK (again 32bit) which also ships with its own MinGW. Due to the fact that I'm not the only one using the system I can't remove the standalone MinGW.
My project is using qmake and is a plain C project (not C++). Everything builds fine but when I try to execute my binary in the command line I get that the application was unable to start due to a missing libgcc_s_dw2-1.dll on the system.
After looking into the issue I found that both the standalone MinGW and the one shipped alongside the Qt SDK have the mentioned DLL.
Standalone MinGW - libgcc_s_dw2-1.dll is located inside the bin subdirectory of the MinGW installation where the binaries are located (gcc, g++, gdb etc.)
Qt MinGW - libgcc_s_dw2-1.dll is located inside C:\Qt\Tools\mingw492_32\i686-w64-mingw32\lib subdirectory while the MinGW components' binaries are inside C:\Qt\Tools\mingw492_32\i686-w64-mingw32\bin.
I would like to know how to properly set my PATH variable so that:
The application starts properly
No conflicts with the standalone MinGW installation occur
Just a side-note: I've already checked other posts here on SO but was unable to find a solution (perhaps I've missed it). I have also tried LIBS += -static but the result is the same.

You just need to copy this dll with your executable, i.e.:
cp <path-to-qt-install-dir>\qt5.7.0\5.7\mingw53_32\bin\libgcc_s_dw2-1.dll <path-to-dest-dir>
You mat find that you have other dependencies, to see which other deps you have you can use: ldd <your-executable>. You only need to copy the qt specific dlls you can see these by:
ldd <executable> | grep -i qt
note
You can statically link it with:
linker commands like -static-libgcc or -static, but I think you start to hit LGPL issues and also you may need to statically compile qt from source - can't recall for this particular file.
note2
Sorry ldd is for linux, just realized you have windows, in which case you can use one or both of:
dependency walker: from here
<path-to-qt-bin-folder>\windeployqt.exe <path-to-your-executable>
I have mixed results with windeployqt, but if you have any plugins its quiet good for getting that part sorted.

Related

Why does MinGW on Windows not need to link statically?

I've installed MinGW on my Linux machine and installed the MinGW package, however, I noticed that I can't run my program on Windows machines that don't have MinGW, I looked it up and soon found that the solution to this is to link statically. This worked, but it's still annoying to have to statically link everything and doesn't make much sense. I noticed that on my Windows machine where MinGW was installed I could compile a program without statically linking anything and the program would run successfully on any Windows machine regardless of whether it had MinGW installed or not.
My Linux box is running Arch Linux and Installed the mingw-w64-gcc AUR packages if that info helps at all.
Linux and Windows shared libraries / dynamically linked libraries are similar in how they get discovered. Your mingw program works in windows that has mingw installed because the installation likely added DLLs to your search path. Check out this article on DLL search order.
When you statically link, all that library code gets included in your executable.
If you want to share your mingw program with friends, then you need to also install all the shared libraries it uses in their search path. You can use sysinternals listdlls (or other tools) to find your dependencies, and include them in the same directory as your exe or install them to a library path (see the search order article).
You can also check out this article; How do I find out which dlls an executable will load? as it has lots of other options.

What files can be safely deleted from the MinGW-w64 binaries?

I am using the MinGW-w64 installer found here:
https://mingw-w64.org/doku.php/download/mingw-builds
Installing to a directory creates a folder called mingw32 or mingw64 that contains the compiler. I already know that the additional batch script, HTML link, and uninstall executable in the same directory can be deleted.
The mingw32/64 folder contains these folders:
bin
etc
include
lib
libexec
licenses
opt
share
i686-w64-mingw32 (mingw32) or x86_64-w64-mingw32 (mingw64)
I only wish to compile with C and nothing else. So what files can I delete in order to reduce the file count because the compiler contains files for Ruby, Fortran and other languages which as I stated, I don't need it.
Why are people still using Mingw or Mingw64 instead of TDM-GCC ? You have to rely on the default builds or build it yourself from source. Trying to install it on your own terms sucks.
TDM-GCC on the other hand, you can specify where and which components to install as you wish. You can upgrade or remove it without any worries. It's more fast, easy,modern and equivelant these days.
Now for your question, you can download and install TDM-GCC by it's installer. I don't really think you need any further instructions as a 5 year old would understand how to use it. Just select only the components required for c.
If you don't understand,I would gladly help you more if needed. ^_^
If you want a smaller GCC toolset, try MinGW Distro.
Scroll down to "How To Build Your Own Distro", download components-14.1.7z, extract it, extract binutils 2.27 and GCC 6.3.0 inside the same folder. The total size is about 270MB.
as far as i know the minimum are yours
1, bin
5. libexec
not all tools in bin you may need but generally i would hold both of those dirs
you also ned libraries and headers if you want to build abainst standard c library and windows.h, so
include
lib
is also needed (hovever part of it may contain also headers and libraries for c++ standard library) all those main 3 libs are kinda mixed there afaik so it might be a bit hard to find what comes for what

Compile for windows using mingw-w64 and autotools

I've this project called librsync.
Installed ubuntu package called mingw-w64. Looked at automake manpage.
What I want to do is to build executable that runs on windows or dll, whichever I could get working.
./configure --host "what do i put here?"
By looking at ubuntu packages I can't figure it out. From automake manpage - If I had mingw32 it should be i586-mingw32msvc. But how do I figure that out on my own in the first place? At least, what should I put in hosts param if I have mingw-w64?
For building something with a cross compiler, you will use configuration-gcc as the C compiler with configuration being what you would pass to --host to build a library or executable.
ls /usr/bin/*mingw*gcc should give you the C compiler to use, allowing you to know what the configuration is.
MinGW (aka mingw32): iX86-pc-mingw32 or iX86-mingw32msvc (X is a 4, 5, or 6 depending on how it was configured)
mingw-w64: ARCH-w64-mingw32 (ARCH is one of i686 or x86_64)
I've honestly not seen anything else for mingw-w64, except in its earlier days when it used ARCH-pc-mingw64, but that shouldn't be used anymore.

How to build gnu `libiconv` on & for windows?

I want to build a static library (*.LIB file) GNU libiconv on windows to be used with other libraries in Visual C++. Other libraries I'm using are built with "MultiThreaded DLL" (/MD) Runtime option. So, I need to build libiconv with the same option.
Problem is the libiconv uses GNU build system and I want to compile with /MD option. You can see the source structure of libiconv here:
http://cvs.savannah.gnu.org/viewvc/libiconv/?root=libiconv
Mr. Zlatkovic maintains the windows port of GNU libiconv for libxml2
you can see them here:
ftp://xmlsoft.org/libxml2/win32/iconv-1.9.2.win32.zip
I cannot use his port. I need to build from the latest version of libiconv-1.13. I wonder how this guy has ported it? Can some one please tell me how to build *.lib from this and compile it using MSVC?
EDIT:
Actually, I need to build few more gnu libraries with same settings. So, if I get solution for one library. I can do the same for all others.
I found PARK Youngho's How to Build libiconv with Microsoft Visual Studio over at The Code Project to be complete and clean (for VS2010 and GNU libiconv 1.14).
A little addition to your answer.
I had the same issue and found that the MinGW + MSYS solution was perfect.
Though, I needed to go a little further and generate also the .lib file in order to be able to link with the resulting dll.
This is what I found:
generate a .def file from the dll with dumpbin (a Visual Studio tool).
generate the .lib file from the .def with the lib program (Visual Studio tool too)
This allows you to specify some link flags if appropriate.
Everything detailed here (I'm not the author of this method):
http://wiki.videolan.org/GenerateLibFromDll
I also realized that this lib/dll couple can be linked with both MD and MDd libraries.
Hope that can help people that find this post, like it helped me.
-David
I'm the OP. MSYS is the exact thing what I was looking for.
Just install MinGW & MSYS which contains shell sh.exe & make.exewith which you can configure and generate a Makefile after that you can use make.exe to run it.
Its as simple as that.
compile them using MinGW using Msys for the environment if needed. MinGW's .a files are apparently, according to the mailing list, the same format as .lib files (just do a rename). You might want to check first to see if the iconv static library is included already in the MinGW download / filesystem.
Edit: it's in msys (C:\msys\1.0\lib), along with:
libiconv.a
libiconv.dll.a
libiconv.la
and additionally
libiconv-2.dll (in C:\msys\1.0\local\bin)
Edit: is it in here, the libiconv you need? these versions seem to have MSVC makefiles :) http://www.opensource.apple.com/source/libiconv/

How to compile a C program?

I haven't done C in a long time. I'd like to compile this program, but I have no idea how to proceed. It seems like the makefile refers to GCC a lot and I've never used GCC.
I just want an executable that will run on windows.
You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.
http://www.mingw.org/
http://www.cygwin.com/
When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:
gcc (try version 2.x first, not 3.x)
binutils
GNU make (or gmake)
If it requires gcc and you want it to run on Windows, you could download Cygwin.
That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.
http://www.cygwin.com/
In order to compile this program you need a C compiler. It does not have to be gcc, although you are already given a makefile set up to use gcc. The simplest thing for you to do would be the following:
Install cygwin
Open the cygwin command prompt
go into the directory where you have your makefile
type 'make'
That should compile your program
If you are not comfortable with using command line tools then you can download the free version of MS Visual Studio and import the source files into a new Visual Studio project. This way you would not need to install cygwin and use gcc, but you would need to know how to create projects and run programs in Visual Studio.
You almost certainly don't need all of cygwin to compile using gcc. There are plenty of standalone gcc clones for Windows, like gcw.
If it's reasonably portable C code (I haven't looked at it), then you may be able to just ignore the included Makefile and feed the source into whatever compiler you do want to use. What happens when you try that?
Dev-C++ provides a simple but nice IDE which uses the Mingw gcc compiler and provides Makefile support. Here are the steps I used to build the above code using Dev-C++ (i.e. this is a "how-to")
After downloading the source zip from NIST, I
downloaded and installed the Dev-C++ 5 beta 9 release
created a new empty project
added all the .c files from sts-2.0\src
Then under Project Options
added -lm in the Linker column under Parameters
added sts-2.0\include to the Include Directories in Directories
set the Executable and Object directories to the obj directory under the Build Options
and then hit OK to close the dialog. Go to Execute > Compile and let it whirl. A minute later, you can find the executable in the sts-2.0\obj directory.
First, there is little chance that a program with only makefiles will build with visual studio, if only because visual studio is not a good C compiler from a standard POV (the math functions in particular are very poorly supported on MS compilers). It may be possible, but it won't be easy, specially if you are not familiar with C. You should really stick to the makefiles instead of trying to import the code in your own IDE - this kind of scienfitic code is clearly meant to be compiled from the command line. It is a test suite, so trying things randomly is NOT a good idea.
You should use mingw + msys to install it: mingw will give you the compilers (gcc, etc...) and msys the shell for the make file to run correctly. Contrary to one other poster, I would advise you against using gcc 2 - I don't see any point in that. I routinely use gcc 3 (and even 4) on windows to build scientific code, it works well when the code is unix-like (which is the standard platform for this kind of code).

Resources