Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: CGO desn't work with gtk on windows. #7981

Closed
mattn opened this issue May 13, 2014 · 6 comments

Comments

@mattn
Copy link
Member

commented May 13, 2014

This code should work correctly

package main

/*
#include <gtk/gtk.h>
void Foo() {
    gtk_init(NULL, NULL);
    GtkWidget* w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show_all(w);
    gtk_main();
}
*/
// #cgo pkg-config: gtk+-2.0
import "C"

func main() {
    C.Foo()
}

But crash at calling gtk_main(). I debug-ed with gdb, but it doesn't reproduce on gdb.
I tried to add runtime.LockOSThread(), but it don't solve.

OS: Windows7 32bit SP1
GO Version: go version devel +e473e77e84ff Wed May 07 13:17:10 2014 -0700 + windows/386
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 13, 2014

Comment 1:

I think it's well understood that gtk requires runtime.LockOSThread.  Can you show us
that version of the program?

Labels changed: added repo-main, release-go1.3maybe, os-windows.

@mattn

This comment has been minimized.

Copy link
Member Author

commented May 13, 2014

Comment 2:

This code doesn't work.
package main
/*
#include <gtk/gtk.h>
void Foo() {
    gtk_init(NULL, NULL);
    GtkWidget* w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show_all(w);
    gtk_main();
}
*/
// #cgo pkg-config: gtk+-2.0
import "C"
import "runtime"
func main() {
    runtime.LockOSThread()
    C.Foo()
}
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 13, 2014

Comment 3:

Thanks.  For the record, it doesn't crash on GNU/Linux (Ubuntu Precise).
@robpike

This comment has been minimized.

Copy link
Contributor

commented May 19, 2014

Comment 4:

Moving to 1.4 - too late for 1.3

Labels changed: added release-go1.4, removed release-go1.3maybe.

@mattn

This comment has been minimized.

Copy link
Member Author

commented Aug 7, 2014

Comment 5:

It seems fixed in latest go in repo.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2014

Comment 6:

Thanks for following up.  I don't know what fixed it, but then I don't know what was
broken.

Status changed to Fixed.

@mattn mattn added fixed labels Aug 7, 2014

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015

@rsc rsc removed the release-go1.4 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.