I'm not a huge fan of spamming StackOverflow with questions, but I've been trying to get this working for the past two days. Here goes...
I've come up with a small reproduction of a basic C++ file that compiles and runs perfectly on Linux (ubuntu), but compiles and results in an immediate SegFault (or constant access violation that seem to happen on the gtkmm event loop) on Windows 10 using the MSYS2 (mingw64) g++ compiler.
For MSYS2, I'm using the mingw-w64-x86_64-gtk3
package, recommended by the docs. My thoughts are that this is a problem during the linking process? No GUI appears, only terminal errors.
The line that causes the problem is specifically App::App : myLabel("HelloWorld") {
.
By initialising the list inside the constructor using label = Gtk::Label("Hello world!");
, the program actually works on Windows 10 as well, although I later found another segfault in another small detail.
I'm quite new to C++, my question is, am I doing something very wrong in my code or is it possible that the gtkmm library just isn't optimized for Windows, or that the binaries are out of date? I imagine that doing a lengthly compilation of the gtkmm source would work? Or am I just making a dumb pointer mistake?
MSYS2 setup:
$ pacman -Syu gcc mingw-w64-x86_64-gtk3
Compiled with:
$ g++ -std=c++11 `pkg-config gtkmm-3.0 --cflags` -o app app.cpp `pkg-config gtkmm-3.0 --libs`
The sample that segfaults:
#include <gtkmm/window.h>
#include <gtkmm/label.h>
#include <string>
// Class prototype
class Window : public Gtk::Window {
public:
Window();
Gtk::Label myLabel;
};
// Entry point, create app and initialise window
int main(int argc, char* argv[]) {
auto app(Gtk::Application::create(argc, argv, "ch.epfl.cemes.marcus.test"));
Window window;
return app->run(window);
};
// Extend Gtk::Window and show some text
Window::Window() : myLabel("Hello world!") { // this line seems to be the problem
add(myLabel);
myLabel.show();
};
Running the compiled executable of the code above on Windows results in the following error filling up the console repeatedly:
Exception code=0xc0000005 flags=0x0 at 0x0000000100401E9C. Access violation - attempting to read data at address 0x0000000021646CC2
My main application, that is practically identical but split into more files, exits immediately with the following:
Exception code=0xc0000005 flags=0x0 at 0x0000000063F14B9D. Access violation - attempting to read data at address 0xFFFFFFFFFFFFFFFF
0 [main] archipelago 1909 cygwin_exception::open_stackdumpfile: Dumping stack trace to archipelago.exe.stackdump
and yields a beautiful file with 15 lines of stack frames.
I appreciate the time you took to read this post. Have a great day!
Look in https://developer.gnome.org/gtkmm/stable/classGtk_1_1Label.html
Seems to me their constructor does not offer char* const
parameter. Use myLabel.set_text("HelloWorld");
instead.
User contributions licensed under CC BY-SA 3.0