PMunch / wxnim

Nim wrapper for wxWidgets.
MIT License
100 stars 11 forks source link

\private\scrolwin.nim(6, 58) Error: cannot convert 3221225472 to clong #21

Open jlp765 opened 3 years ago

jlp765 commented 3 years ago

Error: type mismatch: got but expected 'clong = int32'

On win10 Nim Compiler Version 1.4.2 [Windows: amd64]

Seems to be some problem with 64bit/32bit definition for clong, as it expects int32 but the value is an unsigned 0xC000000

PMunch commented 3 years ago

Good catch! This was something that was changed in Nim at some point (that hex literals can't be negative signed numbers). But it is curious that I haven't seen this issue myself on Linux. Is the clong defined differently between the two platforms?

thomasguo commented 3 years ago

I got the same problem. My env is as follow:

On win7 Nim Compiler Version 1.4.2 [Windows: amd64]

PMunch commented 3 years ago

Was this from just running one of the examples? Or do you have a small code snippet I can try to reproduce this with?

thomasguo commented 3 years ago

I just tested the examples of wxnim, which are in folder examples\purewx . And the wxWidgets version is 3.1.4

PMunch commented 3 years ago

Hmm, I haven't tested with the newer 3.1.4 branch, only the 3.0.5 version. Could you try that?

xbello commented 3 years ago

I get the same error with this minimal example:

import wxnim / [wx, genui]

{.experimental.}

genui:
  mainFrame % Frame(title = "Title")

mainFrame.show()
runMainLoop()

Compiles in linux (wx 3.0.5, nim 1.4.2) using nim cpp minimal.nim, shows the expected empty window.

Fails crosscompiling using nim cpp --cpu:i386 --d:mingw32 minimal.nim with the above error

private/scrolwin.nim(6, 52) Error: 3221225472 can't be converted to clong

Fails compiling in Windows 10 (wx 3.1.4, nim 1.4.2) using nim cpp -d:"wxWidgetsPath:C\wxWidgets-3.1.4" minimal.nim

Installed wx-3.0.5 to get the same error.

xbello commented 3 years ago

But it is curious that I haven't seen this issue myself on Linux. Is the clong defined differently between the two platforms?

So it seems:

https://github.com/nim-lang/Nim/blob/1d8b7aa07ca9989b80dd758d66c7f4ba7dc533f7/lib/system.nim#L1368

PMunch commented 3 years ago

Hmm, that is peculiar. The underlying issue is probably that recent-ish versions of Nim restricted the ways numbers could be converted between signed and unsigned types. I think changing line 6 of scrollwin.nim to wxScrolledWindowStyle* = cast[clong](wxHSCROLL or wxVSCROLL) should fix the issue.

xbello commented 3 years ago

That get rid of the "can't be converted", but the compilation still fails:

g++.exe: error: /IC:\wx\3.0.5\lib\gcc_lib\mswu: Invalid argument

Error: execution of an external compiler program 'g++.exe -c -std=gnu++14 -funsigned-char  -w -fmax-errors=3 -fpermissive -mno-ms-bitfields -DWIN32_LEAN_AND_MEAN -D__WXMSW__ -I"C:\wx\3.0.5\include" /I"C:\wx\3.0.5\lib\gcc_lib\mswu"   -IC:\Users\xbello\AppData\Local\nim-1.4.2\lib -IC:\Users\xbello\source\minimal -o C:\Users\xbello\nimcache\minimal_d\stdlib_io.nim.cpp.o C:\Users\xbello\nimcache\minimal_d\stdlib_io.nim.cpp' failed with exit code: 1

g++.exe: error: /IC:\wx\3.0.5\lib\gcc_lib\mswu: Invalid argument
PMunch commented 3 years ago

I think that's a completely separate issue, probably caused by this https://github.com/PMunch/wxnim/blob/master/wxnim/wxCompile.nim#L67. Someone else implemented this, so I don't really have much to go on here. Maybe @fredrikhr could help out?

fredrikhr commented 3 years ago

Ooops. That's a copy-paste error that has been there a loooong time 😮

It seems that I just copied https://github.com/PMunch/wxnim/blob/2250d019d5566c254a039ccfc81dd4110136a673/wxnim/wxCompile.nim#L29 and forgot to adjust that VCC uses /I for include, but G++ does not.

The fix is to change /I in line 67 to the correct flag in G++ or Clang. I guess that would be -I instead, right?