How to Do Static Linking of Libwinpthread-1.Dll in Mingw

how to do static linking of libwinpthread-1.dll in mingw?

You should probably check command line options documentation for GCC.

These's no '-static-something' command, only standard libraries (libgcc and libstdc++) can be set to static linking with one command. For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, ie "-lpthread".

Mingw32 failing to statically link to libgcc_s_dw2-1, libstdc++-6, libwinpthread-1 (Qt 5.7.1)

If your build and it's dependancies aren't static, those DLLs need to be distributed with your application.
The article at https://lwn.net/Articles/549573/ explains the libstdc++-6 DLL can be distributed without licensing issues.

pthreads static linking with MinGW

With the new updated version of MinGW you can get version 2.10 of pthread-win32 library. Among several changes and bug fixes, you could find the possibility to statically link it.
You only need to include -lpthread in the list of static libraries.

Following is an example mixing static linking with the pthread library and dynamic linking with a Windows library:

mingw32-gcc.exe -o sample.exe sample.c -Wl,-Bstatic -lpthread -Wl,-Bdynamic -lws2_32

With this, you also release the dependency on libgcc_s_dw2-1.dll

creating a project on mingw under windows

A C++ program needs runtime libraries to run. They're usually not part of the program itself! So you'd need to ship these libraries alongside with your program (which is what most software does).

You can, for many things, however, also use "static linking", which means that the parts of the libraries used by your program are included in your program itself! The -static flag supplied to executable-generating step in your project will do that. If your program consists of but a single file, that would be g++ -o test -static test.c (your g++ might be called x86_64-w64-mingw32-g++ or so).

How to dynamically link to DLL (Dynamic-link library) when using MinGW?

I was missing -L. option at my command. It works:

gcc -o nonamed.exe main.c -L. -lsqlite3

Alternatively you can do:

gcc -o nonamed.exe main.c sqlite3.dll

Can't cross compile C++ files in MinGW properly

To build a fully static file you should not only use -static-libgcc and/or -static-libstdc++, but also -static to tell the linker to include static versions of any other libraries.

Or you can just build the shared library, but then you will need to distribute any DLL the EXE depends on it with the EXE and put the DLL in the same path as the EXE (or anywhere in a location listed in the PATH environment variable).

I wrote a tool called copypedeps as part of https://github.com/brechtsanders/pedeps to copy just those dependencies.



Related Topics



Leave a reply



Submit