Open araoko opened 6 years ago
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
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
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
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?
Could you put together a small repo demonstrating your issue, @araoko, such that we can take a look at it ourselves?
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?