-1

EDIT: Thanks random downvoter!

EDIT 2: Thanks @πάνταῥεῖ for explaining what was wrong with the question. When running a debugger I get

Program received signal SIGSEGV, Segmentation fault.
0x0046f4c6 in ?? ()

EDIT 3: This only happens if I run the cross compiled program. If I compile the program in Windows and run it with WINE, nothing wrong happens.

So well, I'm fighting with WINE and MinGW32 right now. So I have a file, sortem.cpp which is compiled with a Makefile and linked and all from that Makefile.

sortem.cpp

#include <windows.h>
#include <iostream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

int main ()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(720,480),"Sort 'em!");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
            {
                window.clear();
                switch (event.type)
                {
                    case sf::Event::Closed:
                        window.close();
                }
                window.display();
            }
    }
    return 0;
}

Makefile

LD = ../bin
LIBS= $(LD)/sfml-window-2.dll $(LD)/sfml-system-2.dll $(LD)/sfml-graphics-2.dll $(LD)/sfml-network-2.dll $(LD)/sfml-audio-2.dll
OBJECTS= sortem.o
CXX= i586-mingw32msvc-g++
all: sortem.exe

sortem.exe: $(OBJECTS)
     $(CXX) -o ../bin/sortem.exe $(OBJECTS) $(LIBS)

%.o: %.cpp 
    $(CXX) -c $<

clean:
     rm *.o 

So the program compiles perfectly, but when running sortem.exe with WINE, it says the program must exit. I click "Show details" and this pops up. Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x0046f4c6).and a lot of hexdumps. I really don't know what I'm doing wrong, maybe the SFML libraries aren't up to date? But that'd give me a compile error, not a runtime error... Thanks a lot for the help, guys.

ChemiCalChems
  • 612
  • 12
  • 31
  • It wasn't a _random downvote_! Your question is lacking a lot of information necessary to solve your problem. 1st: What did you notice, when running your program in the debugger? 2nd: What are the stack traces actually telling you? etc. – πάντα ῥεῖ Feb 08 '15 at 12:00
  • @πάνταῥεῖ Then a comment, like yours, would be very much appreciated. – ChemiCalChems Feb 08 '15 at 12:05
  • 1
    It's generally expected on SO you do all of the mentioned efforts beforehand asking. So it's not necessary to leave comments on bad questions. – πάντα ῥεῖ Feb 08 '15 at 12:08
  • @πάνταῥεῖ Excuse my error then. I'm adding an edit right now to address your 1st demand. – ChemiCalChems Feb 08 '15 at 12:08
  • 2
    If you type `bt` or `where` into gdb, it will show you where you came from before the crash. This is most of the time a good place to start typing `up` to see what your code was actually doing. Something is obviously NULL that isn't expected to be NULL. – Mats Petersson Feb 08 '15 at 12:14
  • @MatsPetersson 0x0046f4c6 in ?? () doesn't look good at all. I expected a function name. Does this have something to do with the fact that wine is running the program? – ChemiCalChems Feb 08 '15 at 12:18
  • @ChemiCalChems Step upwards the stack, to see where you came from. – πάντα ῥεῖ Feb 08 '15 at 12:26
  • @πάνταῥεῖ keep getting (ADDRESS) in () ??. No function names are ever shown. But wait a second... If there are entries for 0 to 10... Does that mean the error is ocurring at line 11? That could be something. Seems to lead to window.display(); – ChemiCalChems Feb 08 '15 at 12:29
  • May want to actually generate debug symbols using the `-g` option in your compile. (e.g. `$(CXX) -g -c $<`) – Mats Petersson Feb 08 '15 at 13:23
  • @MatsPetersson Thanks, but its working now with another toolchain. – ChemiCalChems Feb 08 '15 at 13:31
  • I saw that, but you will need to learn to debug at some point - unless getting that bit of program to work was your last ever project... – Mats Petersson Feb 08 '15 at 13:40
  • @MatsPetersson In fact, it's failing again. I think it's WINE's fault. You are right. I should do that, and learn how to debug a program. Sorry for my ignorance. – ChemiCalChems Feb 08 '15 at 16:06
  • So, add -g to your compile and link command, and you SHOULD get a better backtrace. I doubt that you are exposing bugs in Wine with a simple program - more likely you are hitting some undefined behaviour due to something you do in your code... ;) – Mats Petersson Feb 08 '15 at 16:14
  • @MatsPetersson Actually, the program works perfectly on Windows. I'm installing a Virtual Machine for that right now, and I'll test. If it works on the VM and not on Ubuntu, it's WINE's fault. Otherwise, I'll debug. – ChemiCalChems Feb 08 '15 at 16:57
  • @MatsPetersson, if I compile my program with g++ 4.8.2 and the dlls are compiled with g++ 4.8.1 they wont work will they? Thats what may be happenning – ChemiCalChems Feb 08 '15 at 19:31

1 Answers1

0

The libraries were compiled with MinGW GCC 4.7.1 and I was trying to compile my program with MinGW GCC 4.8.1, downgraded thanks to a friend and back online it is. Thanks you guys all for having shown me how to debug. Peace

ChemiCalChems
  • 612
  • 12
  • 31