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

Debugging WxGo #57

Open
araoko opened this issue Apr 8, 2018 · 5 comments
Open

Debugging WxGo #57

araoko opened this issue Apr 8, 2018 · 5 comments

Comments

@araoko
Copy link

araoko commented Apr 8, 2018

I wrote a class to wrap a wx.Window, i must be doing something wrong because my program stopped running. all i got was exit status 2. i cant write to stdout or stderr so its difficult for me to trace the problem.
i decided to run a debugger and that failed too with error "go build github.com/dontpanic92/wxGo/wx: invalid flag in #cgo LDFLAGS: -Wl,--subsystem,windows".
i am stuck. how do we debug our code if it fails before showing a window?

@dontpanic92
Copy link
Owner

I guess you are using Windows - on Linux, the stdout & stderr should be available by default.
On Windows, if you want to print to stdout / stderr in a "Windows" subsystem (instead of the "Console" subsystem), you can use AllocConsole + freopen. Basically,

(untested code)

#include <windows.h>

void EnableStdOut()
{
  AllocConsole();
  freopen("CONOUT$", "w", stdout);
  freopen("CONOUT$", "w", stderr);
}

Regarding the debugger issue, I think it seems related with #44

@araoko
Copy link
Author

araoko commented Apr 8, 2018

I built (go build) and ran the program on 64bit windows 10 PC.
how do i use your code in a Go application? i don't know AllocConsole or freopen.
i am using the Go debugging feature of VSCode on windows 10

@dontpanic92
Copy link
Owner

dontpanic92 commented Apr 8, 2018

You can use cgo to embed C code in a Go program. For example,

package main

// #include <...>
// void EnableStdOut()
// {
// ... /*More C Code Here*/
// }
import "C"

func main() {
  C.EnableStdOut()
}

VSCode supports adding environment variables when starting programs (I found the VSCode doc here). Try to add {"CGO_LDFLAGS_ALLOW": ".*"} to the env field

@araoko
Copy link
Author

araoko commented Apr 13, 2018

I could not get the debugging or writing to console work satisfactorily. i decided to use the log package to log to file with worked well. from the log i discovered that the error is from my call to a NewWindow func. the function returns just window and no error object, in fact the entire API has no error component. How do we detect/handle errors?

@Asday
Copy link

Asday commented Aug 17, 2018

Could you put together a small repo demonstrating your issue, @araoko, such that we can take a look at it ourselves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants