I use nim in MSYS2+Mingw64 on Windows 7 64 bits.
The involved code can be download here which uses wxnim . And I have stated the details to compile wxWidgets
First of all
I can compile and run the CPP version by PB, no matter with
g++ -Os `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)`
or
g++ `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)`
Then for the nim code
I use
$ nim
Nim Compiler Version 0.19.9 [Windows: amd64]
Compiled at 2019-01-28
Copyright (c) 2006-2018 by Andreas Rumpf
$ nim cpp -r -d:release --passL:-s --opt:size example2.nim | the EXE runs without crash |
---|---|
$ nim cpp -r -d:release --passL:-s example2.nim | the EXE runs and crash |
$ nim cpp -r -d:release --opt:size example2.nim | the EXE runs without crash |
$ nim cpp -r -d:release example2.nim | the EXE runs and crash |
all the crashes says
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: 'C:\Users\USER\.nimble\pkgs\wxnim-0.8.0\examples\purewx\example2.exe '
of cause, all the EXE files have different file size.
so what is the problem and how to fix it? Thanks
Maybe you have forgotten the binding, but I am using wxnim from PMunch fork from you, Araq, it is not my wrapping code. And the example2 is in the wxnim too.
nim cpp -r -d:useSysAssert -d:useGcAssert example2.nim
says
Traceback (most recent call last)
example2.nim(7) example2
example2.nim(40) createFrame
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
where
line 07 let f = createFrame()
line 40 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, constructWxColour(75, 75, 75) )
line 41 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, constructWxColour(220, 220, 220))
if I comment out line 40 and 41, then the compiled EXE can run without crash. I am puzzled why line 7 can passed this time
If I change line 40, 41 to
line 40 var c1 = cnew constructWxColour(75, 75, 75)
line 41 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, c1 )
line 42 var c2 = cnew constructWxColour(220, 220, 220)
line 43 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, c2)
then I get
example2.nim(41, 7) Error: type mismatch: got <ptr WxStyledTextCtrl, int literal(33), ptr WxColour>
but expected one of:
proc styleSetForeground(this: var WxStyledTextCtrl; style: cint; fore: WxColour)
first type mismatch at position: 3
required type: WxColour
but expression 'c1' is of type: ptr WxColour
1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: styleSetForeground(text, 33, c1)
I still don't know how to fix it
this helped me before: import segfaults
it inserts a signal handler and outputs a stacktrace.