MinGW .exe requires a few gcc dll's regardless of the code?
Your commands are wrong !
Go to the directory where your main.cpp file is, and try the following.
g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o
then you'll no longer need to copy the DLLs (for your Hello World program).
Other notes:
The MinGW installation instructions recommends setting
c:\minGW;c:\MinGW\bin;
to the PATH environment variable.
Normally the
-static -static-libgcc -static-libstdc++
linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll
.
Also, try to clean
before recompiling.
There's no "-static-something" command.
Only standard libraries libgcc and libstdc++ can be set to static linking.
For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".
Cmake users should try adding:
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
c++ 17 std::filesystem can not run on other (windows 10) computer
Did you check that the
libstdc++-6.dll
Is available or the relevant libraries are statically included static linked libs
C++ code compiled with cygwin needs cygwin1.dll to run
As discussed in comments, the native gcc
inside Cygwin targets Cygwin. You want the GCC targeting mingw32 not the one targeting Cygwin. While you can install that GCC inside Cygwin as a cross compiler, the native GCC from MSYS works just fine and I too would recommend that.
Note that if you need a library that isn't available in MINGW, pulling the one from Cygwin will essentially never work. Consider this a hard line: never mix Cygwin dependent dlls with non-Cygwin dependent dlls. Treat Cygwin as a subsystem that happens to be startable directly from Win32 rather than a Win32 library.
MINGW has had pthread for awhile; however many times the port doesn't work. If the pthread-using program calls fork(), it will not work. That's when you need Cygwin.
Missing libgcc_s_seh-1.dll starting the .exe on Windows
I found the cause of my problem: I had two MingGW installations on my machine. Once the installation that comes with CLion and a separate one. The latter did not have the required dll. However, CLion used its own installation, which in turn owns the DLL. So the solution was to remove the separate installation and include the path to the CLion installation's bin/ directory in the PATH environment variable.
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).
Related Topics
Sorting Two Corresponding Arrays
Const Correctness for Value Parameters
How to Get a Copy of the File Libstdc++.So.6.0.15
Splitting a String into an Array in C++ Without Using Vector
How to Get a List of Video Capture Devices (Web Cameras) on Linux ( Ubuntu )? (C/C++)
How to Set File Permissions (Cross Platform) in C++
How to Use String.Substr() Function
Detect If Program Is Running with Full Administrator Rights
False Positive with Is_Copy_Constructible on Vector<Unique_Ptr>
Why Stdfax.H Should Be the First Include on Mfc Applications
How to Have Swift, Objective-C, C and C++ Files in the Same Xcode Project
Very Poor Boost::Lexical_Cast Performance
Fast N Choose K Mod P for Large N
What Do C and Assembler Actually Compile To
Reorder Vector Using a Vector of Indices
Multiple Preincrement Operations on a Variable in C++(C )
How to Generate All Permutations of an Array in Sorted Order