Skip to content

Issue with Foreign Function Interface (FFI) and Graphics in Version 12.27 Console (Win_64) #280

Open

Description

@luizmoura1

Hello SmallBASIC Team,

I am experiencing persistent issues with SmallBASIC version 12.27 (Console Win_64, Apr 26 2024) on Windows 10/11. I am trying to use the Raylib plugin, but I've encountered several roadblocks that seem related to the interpreter's core handling of external libraries and internal modules.

Technical Environment:

OS: Windows (AMD64)

Version: SmallBASIC 12.27 Console Win_64

Library: libraylib.dll (confirmed to be in the path/folder)

The Issues encountered:

FFI Syntax Errors: When attempting to use export or dlopen within a unit, the interpreter frequently returns Variable is NOT an array or Undefined SUB/FUNC code: EXTERN, even when following standard documentation for plugin headers.

Case Sensitivity/Symbol Lookup: Even after confirming via binary inspection that a symbol exists (e.g., INITWINDOW), the interpreter fails to link it, returning Export symbol 'INITWINDOW' not found.

Core Modules Missing: Surprisingly, the native graphics command returns Undefined SUB/FUNC code: GRAPHICS in this specific Console Win_64 build, preventing even basic non-plugin drawing.

Process Hang: Some attempts to load external DLLs results in a hanging cursor (infinite loop) without any error output or window initialization.

Could you clarify if the 12.27 Win_64 Console build has known limitations regarding the Graphics module or if there is a specific requirement for the libraylib.dll architecture (32 vs 64 bit) and naming convention (StdCall/Cdecl) to work with this version?

Best regards,
Luiz

Activity

  1. luizmoura1 commented on Mar 8, 2026

    @luizmoura1
    Author

    I've found the cause of the 'Unit not found' error and would like to share my findings to help others:

    Local Dependency: On Windows (SmallBASIC 12.27), the Raylib DLLs must be in the same folder as the .bas script being executed. Even if the main sbasic.exe is in the system PATH, the interpreter fails to load the third-party libraries if they are not present in the script's current working directory.

    The .sbu File Mystery: I performed comparative tests and confirmed that SmallBASIC only generates the .sbu file when the Unit contains executable code (sub or func). Since my raylibc.bas unit contains only export const definitions, the interpreter treats it as a data header in memory and does not compile a binary bytecode file to disk. This is why the .sbu was 'missing' even when the code worked.

    Misleading Error Message: When the DLLs were missing from the subfolder, SmallBASIC failed the import process and incorrectly reported that the Unit was 'not found'. In reality, it was the absence of the DLLs that blocked the process.

    By placing the 10 DLLs and the raylibc.bas file in the same folder as the script, everything works perfectly via the terminal (e.g., sbasic janela1.bas).

  2. Joe7M commented on Mar 9, 2026

    @Joe7M
    Contributor

    Sorry for the confusion. You are right, the info in the raylib article is not correct. I'll clarify this in the article.

    An additional option is to point sbasic to the right DLL folder at startup:

    sbasic.exe -m PATH_TO_DLL myprogram.bas
    

    PATH_TO_DLL can be an absolute path like C:\myfolder or a relative path like ./mydlls. The relative path is relative to the location of you program. raylibc.bas still needs to be in the same folder as your prgram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions