Compiling with MinGW crashes while Cygwin works - c++

I'm writing a simple roguelike, and I was compiling statically to test, but I found that the program a) crashes when input is given, and b) does not seem to randomize at all when I compiled with MinGW. I switched over to Cygwin to check it out, and found that the statically-compiled version with Cygwin performed exactly as expected. I used the same commands for both: g++ -c FILE_NAME -std=c++14 -lncurses for each source file, then g++ -static -o dngn OBJECTS -std=c++14 -lncurses to link the final build.
The MinGW build:
mingw.png
The Cygwin build:
cygwin.png
Both images are screengrabs of it running with the respective compiler

Related

cairo and librsvg statically linked with "dll.a" don't run outside mingw

I found this example over the internet, on how to use librsvg, it compiles on mingw, and it runs, but it does not run outside mingw context. (For example going to explorer and double clicking the file).
The error is:
the code execution cannot proceed because librsvg-2-2.dll was not found. reinstalling the program may fix this problem.
the code execution cannot proceed because libcairo-2.dll was not found. reinstalling the program may fix this problem.
Now, I want to run this code outside mingw, but it doesn't find the cairo and librsvg dlls, (I have no .dlls only .dll.a files), running it inside mingw works perfectly.
These are my compilation flags. (I changed the name from main.c to main.cpp)
How can I make this code run, in this case?
g++ -c main.cpp -o main.o -I/mingw64/include/librsvg-2.0 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include/cairo -I/mingw64/include/gdk-pixbuf-2.0
g++ main.o -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread /mingw64/lib/libcairo.dll.a /mingw64/lib/librsvg-2.dll.a -o main.exe

Running a SFML C++ program with minGW on Windows 10

So I'm trying to run an example SFML program on my Windows laptop. If relevant, the source code is on this page.
So first I make the .o file using this command -
g++ -c a.cpp -ISFML/SFML/include
Where a.cpp is the main file, and my SFML package is located in SFML/SFML.
Then I compile using this command -
g++ a.o -o a -LSFML/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
When I first ran the program I got the errors about not being able to find certain dlls, sfml-graphics-2 etc. So I found them and put them next to the exe. But now when I run, I get this weird error:
The procedure entry point
_ZNSt7__cxx1112basic_stringSt11char_traitsIcESalcEE7reserveEj could not be located in the dynamic link library.
What is going on here?
As the SFML download page states, You could be using the wrong version of the compiler, other library versions of SFML that you have not removed from your working directory that could mismatch between code and linker. Worst case, if your compiler is not listed there, you have to compile SFML yourself:
Get CMake. Get the source code for 2.4.2 by going to the bottom of the SFML download page. Follow this guide on SFML's GitHub repo. Alternatively, you could use the guide on SFML's page but it is for an older version. It might answer some questions that the first guide misses.
Ones CMake have generated the makefiles, you're on your way to build SFML.
Good luck!
I've had this problem for so long so I just wanted to help someone out who had the same problem. I have a windows 10 FYI and MinGW-w64 8.1.0 (if it doesnt work try a 32 bit mingw instead)
for a debug mode (debug is when your still working on the game and would like command prompt to open whenever you run it)
(make sure your in the right directory first by doing "cd")
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -g -m64 -Wall &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics -lsfml-window -lsfml-system
The code above when placed in command will compile everything for you if its all in the same directory so make sure you keep an eye out for that
and now for release mode (if you dont want command prompt to show up)
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -O3 -m64 &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics lsfml-window -lsfml-system -mwindows
Noticed all I added was the -mwindows and the -O3 aswell as removing -g and -Wall which are not necessary since we wont be using command prompt
Make sure to go to SFML/bin and take all the .dlls and put it into the same directory has your .exe sorry xd
Hope this helped.

Moxa PComm.lib with g++ under mingw64: file format not recognized

I am refactoring an old Borland C/C++98 program. I would like to program it under linux platform but to beginning, as I have severals additionnals boards, I clean the program, remove all GUI OWL and make tests under win7 and mingw64 to use modern gcc/g++.
I actually try to link a sample code that use C320 turbo Moxa multiport serial board.
As mentionned in
http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use
it should link .lib and .dll.
So I tried to link my sample with Moxa PComm.lib for sio_open, sio_read, sio_write… functions as
g++ -m32 -Wall -std=c++14 src/main.cpp src/rs232_c320t.cpp … -L./lib -lPComm
and it returns
./lib/PComm.lib: file not recognized: File format not recognized
Are there any options to allow link windows .lib with gcc/g++ under mingw64?
Thanks
This related "Linking *.lib files with MinGW" question doesn't mention "File format not recognize" error. See also my comments below.
bcag2
I downloaded last PCommLite for win7 x64.
Copy C:\Program Files\Moxa\PCommLite 1.6\Include\PCOMM.H in my include project folder (lib in my case), and do the same for files PCOMM.dll and PCOMM.lib in C:\Program Files\Moxa\PCommLite 1.6\Lib\x64.
Then I compile with:
g++ -c -std=c++14 -D_hypot=hypot -DWIN32 src/*.cpp -I./lib/
Where -I./lib give access to PCOMM.H and link with:
g++ -shared *.o lib/PCOMM.LIB /c/Windows/System32/msvcr120.dll /c/ProgramData/Anaconda3/python36.dll -o _project.pyd
Of course you can do all in one time and create an .exe:
g++ -o project.exe -Wall -std=c++14 -DWIN32 src/*.cpp -Ilib/ lib/PCOMM.LIB -L./lib/
NO -ansi required as suggested by Moxa support!

Command line arguments with CodeBlocks

So, I have been using CodeBlocks IDE for compiling my C and C++ programs. But I want to run the program from the command line. How do I go about this?
P.S I want to run it on Windows platform.
If you want to build a Code::Blocks workspace from the command line, use codeblocks.exe --build --target=W32_Release --no-batch-window-close MyApp.workspace where MyApp.workspace is your workspace. If you want to build a program from the command line without using Code::Blocks, use gcc -O2 program.c -o program where program.c is your program, or g++ -O2 program.cpp -o program for C++. You can get gcc & g++ from here.

gdb not debugging mingw32-g++ compiled code well, but works with g++

I have a simple c++ program I'd like to debug with gdb. When I compile it with
g++ -g main.cpp -o main.exe
I can use gdb just fine with the resulting executable. But when I use
mingw32-g++ -g main.cpp -o main.exe
gdb says things such as
in ?? ()
and functionality is limited; I seem to be able to set break points and run the program, but stepping and such yields the message
Cannot find bounds of current function
As I said, this only happens when compiling with the mingw32-g++ executable, and not with the plain g++ one.
Why is this, and how can I debug executables created with migw32-g++? Both executables run without issue.
Extra info:
Am on Windows 7.
g++ version: 4.8.2
mingw32-g++ version: 4.8.1
gdb version: 7.6.50.[lots of numbers]-cvs
If there's any other info I can provide to help find the issue, just let me know.