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

WxNim either fails with undeclared indentifier or crashes compiler when I try to cross-compile for Windows on Ubuntu. #30

Open
fabricio-p opened this issue Jun 12, 2024 · 4 comments

Comments

@fabricio-p
Copy link

Basic information

build machine:

  • architecture: x86_64
  • OS: Ubuntu 22.04 LTS

target machine:

  • architecture: x86_64
  • OS: Windows

nim --version:

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-08
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 09b5ed251e4f9a47af7a0176ea4632bebdfd506a
active boot switches: -d:release

Steps taken

  1. nimble init project-name && cd project-name
  2. nimble install wxnim
  3. echo 'requires "wxnim#head"' >> project-name.nims
  4. nvim src/project-name.nim and write
    import wxnim/[wx, genui]
    
    {.experimental: "implicitDeref".}
    
    {.emit: "#include <wx/spinctrl.h>".}
    
    var cbChoices = @["Combobox 1", "Combobox 2", "Combobox 3"]
    
    
    var
      spinner: ptr WxSpinCtrl
      slider: ptr WxSlider
      gauge: ptr WxGauge
    
    proc spinnerCallback(e: varWxSpinEvent) {.cdecl.} =
      let val = e.getPosition()
      spinner.setValue(val)
      gauge.setVal(val)
    
    genui:
      mainFrame % Frame(title = "Hello world"):
        Panel | Boxsizer(orient = wxHorizontal):
          StaticBox(label = "Basic controls")[proportion = 1] | StaticBoxSizer(orient = wxVertical):
            Button: "Button"
    
        CheckBox: "Checkbox"
        TextCtrl(value = "Entry")
        StaticText: "Label"
  5. nvim config.nims and write
    --define:"wxWidgetsPath:wxwidgets-mingw"
    --define:"mingw"
  6. Download the headers and libraries from https://www.wxwidgets.org/downloads/ under the MinGW-w64 8.1 label for x86_64. The headers from https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.5/wxWidgets-3.2.5-headers.7z and the libraries from https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.5/wxMSW-3.2.5_gcc810_x64_ReleaseDLL.7z
  7. mkdir wxwidgets-mingw and unzip the downloaded archives into that directory.
  8. nimble build
         Info:  Dependency on wxnim@#head already satisfied
      Verifying dependencies for wxnim@0.9
       Building project-name/project-name using c backend
    fatal.nim(53)            sysFatal
    Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkEmpty' [FieldDefect]
           Tip: 4 messages have been suppressed, use --verbose to show them.
    nimble.nim(304)          buildFromDir
    
        Error:  Build failed for the package: project-name
    
  9. nim_dbg cpp src/project-name.nim
    Hint: used config file '/home/fabricio/projects/third-party/Nim/config/nim.cfg' [Conf]
    Hint: used config file '/home/fabricio/projects/third-party/Nim/config/config.nims' [Conf]
    Hint: used config file '/home/fabricio/projects/nim/project-name/config.nims' [Conf]
    .................................................................................................................../home/fabricio/projects/third-party/Nim/compiler/nim.nim(169) nim
    /home/fabricio/projects/third-party/Nim/compiler/nim.nim(124) handleCmdLine
    /home/fabricio/projects/third-party/Nim/compiler/main.nim(338) mainCommand
    /home/fabricio/projects/third-party/Nim/compiler/main.nim(305) compileToBackend
    /home/fabricio/projects/third-party/Nim/compiler/main.nim(142) commandCompileToC
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(325) compilePipelineProject
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(245) compilePipelineModule
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(187) processPipelineModule
    /home/fabricio/projects/third-party/Nim/compiler/sem.nim(822) semWithPContext
    /home/fabricio/projects/third-party/Nim/compiler/sem.nim(784) semStmtAndGenerateGenerics
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2888) semStmt
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(1190) semExprNoType
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(3369) semExpr /home/fabricio/projects/nim/project-name/src/project-name.nim(1, 1) nkStmtList
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2835) semStmtList
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(3402) semExpr /home/fabricio/projects/nim/project-name/src/project-name.nim(1, 1) nkImportStmt
    /home/fabricio/projects/third-party/Nim/compiler/importer.nim(364) evalImport
    /home/fabricio/projects/third-party/Nim/compiler/importer.nim(334) impMod
    /home/fabricio/projects/third-party/Nim/compiler/importer.nim(292) myImportModule
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(284) importPipelineModule
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(245) compilePipelineModule
    /home/fabricio/projects/third-party/Nim/compiler/pipelines.nim(187) processPipelineModule
    /home/fabricio/projects/third-party/Nim/compiler/sem.nim(822) semWithPContext
    /home/fabricio/projects/third-party/Nim/compiler/sem.nim(784) semStmtAndGenerateGenerics
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2888) semStmt
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(1190) semExprNoType
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(3369) semExpr /home/fabricio/.nimble/pkgs2/wxnim-0.9-30842e9ec6c93c002349de587f1692fea0b2ace4/wxnim/wx.nim(6, 1) nkStmtList
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2835) semStmtList
    /home/fabricio/projects/third-party/Nim/compiler/semexprs.nim(3387) semExpr /home/fabricio/.nimble/pkgs2/wxnim-0.9-30842e9ec6c93c002349de587f1692fea0b2ace4/wxnim/private/list.nim(53, 1) nkProcDef
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2649) semProc
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2533) semProcAux
    /home/fabricio/projects/third-party/Nim/compiler/semstmts.nim(2306) semCppMember
    /home/fabricio/projects/third-party/Nim/lib/system/fatal.nim(53) sysFatal
    Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkEmpty' [FieldDefect]
    
  10. Append --define:"windows" to config.nims
  11. nimble build
      Verifying dependencies for project-name@0.0.0
         Info:  Dependency on wxnim@#head already satisfied
      Verifying dependencies for wxnim@0.9
       Building project-name/project-name using c backend
    /home/fabricio/projects/third-party/Nim/lib/std/typedthreads.nim(187, 25) Error: undeclared identifier: 'pthread_join'
           Tip: 4 messages have been suppressed, use --verbose to show them.
    nimble.nim(304)          buildFromDir
    
        Error:  Build failed for the package: project-name
    
@PMunch
Copy link
Owner

PMunch commented Jun 18, 2024

Sorry for not getting back to you sooner, been busy lately. Just pushed a version to fix some issues with Nim 2.0.6. However I see you use 2.1.1 which is an unstable development version. I can't reproduce your errors with the stable version, so I have to assume it's a bug in whatever development version you where using. I also tried your code and apart from some typos it also seems to have some logic errors. Below is my updated version which works fine:

import wxnim/[wx, genui]

var cbChoices = @["Combobox 1", "Combobox 2", "Combobox 3"]

var
  spinner: ptr WxSpinCtrl
  slider: ptr WxSlider
  gauge: ptr WxGauge

proc spinnerCallback(e: var WxSpinEvent) {.cdecl.} =
  let val = e.getPosition()
  spinner.setValue(val)
  gauge.setValue(val)

genui:
  mainFrame % Frame(title = "Hello world") | Boxsizer(orient = wxVertical):
    Panel | Boxsizer(orient = wxHorizontal):
      StaticBox(label = "Basic controls")[proportion = 1] | StaticBoxSizer(orient = wxVertical):
        Button: "Button"

    CheckBox: "Checkbox"
    TextCtrl(value = "Entry")
    StaticText: "Label"

mainFrame.show()
runMainLoop()

@fabricio-p
Copy link
Author

The code sample is a subset of the example here https://github.com/PMunch/wxnim/blob/master/examples/genuimacro/controlgallery.nim

@PMunch
Copy link
Owner

PMunch commented Jun 21, 2024

Yes I recognized the code. But when I now full the latest version of this repo it builds fine with the latest Nim version. So I'm unable to reproduce your issue. Did you try to upgrade to the latest stable Nim version and the latest version of wxnim? Keep in mind that old versions still in .nimble/pkgs might override those in .nimble/pkgs2, so best delete the entire old package cache.

@fabricio-p
Copy link
Author

I have only ~/.nimble/pkgs2. Are you trying to cross-compile it from linux using mingw toolchain?

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

2 participants