• Struggling with Tcl C API

    From Frizzus@loic.canin@murena.io to comp.lang.tcl on Wed Oct 15 21:35:04 2025
    From Newsgroup: comp.lang.tcl

    It's my first time trying to port a C project to TCL.

    I'm having difficulties with some "undefined symbol" error when loading
    the library to tclsh.

    ---
    $ make
    gcc ./src/raylib/unity.c ./vendor/raylib/src/libraylib.a -shared -o liblst_raylib.so -DUSE_TCL_STUBS -ltclstub8.6 -ggdb -Wall -Werror -fsanitize=address -fPIC
    echo "TODO : load liblst_raylib.so"
    TODO : load liblst_raylib.so
    # preloading libasan.so librairy for address sanitazation LD_PRELOAD=/usr/lib64/gcc/x86_64-solus-linux/15/../../../../lib64/libasan.so tclsh
    % load ./liblst_raylib.so
    cannot find symbol "Lst_raylib_Init": /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so: undefined symbol: _Lst_raylib_Init
    %
    ---

    I've tried looking for "_Lst_raylib_Init" in my whole project.
    I even tried greping through the C code after preprocessing ( with gcc
    -E command ).

    This symbol is not even called once in the entirety of the source code.
    Did this kind of error append to one of you ?


    The C project github : https://github.com/nicbarker/clay
    My code repo : https://codeberg.org/Frizzus/Lime-Stained-Terracota
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Wed Oct 15 19:50:44 2025
    From Newsgroup: comp.lang.tcl

    Tcl shared library mocules *must* include an Init function. Did you write an Init? The Init function needs to do several things, including:
    call Tcl_InitStubs to initialize the stubs library
    (optionally) call Tcl_PkgProvide to "anounce" the package and its version.
    plus any other setup needed.
    At Wed, 15 Oct 2025 21:35:04 +0200 Frizzus <loic.canin@murena.io> wrote:

    It's my first time trying to port a C project to TCL.

    I'm having difficulties with some "undefined symbol" error when loading
    the library to tclsh.

    ---
    $ make
    gcc ./src/raylib/unity.c ./vendor/raylib/src/libraylib.a -shared -o liblst_raylib.so -DUSE_TCL_STUBS -ltclstub8.6 -ggdb -Wall -Werror -fsanitize=address -fPIC
    echo "TODO : load liblst_raylib.so"
    TODO : load liblst_raylib.so
    # preloading libasan.so librairy for address sanitazation LD_PRELOAD=/usr/lib64/gcc/x86_64-solus-linux/15/../../../../lib64/libasan.so tclsh
    % load ./liblst_raylib.so
    cannot find symbol "Lst_raylib_Init": /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so: undefined symbol: _Lst_raylib_Init
    %
    ---

    I've tried looking for "_Lst_raylib_Init" in my whole project.
    I even tried greping through the C code after preprocessing ( with gcc
    -E command ).

    This symbol is not even called once in the entirety of the source code.
    Did this kind of error append to one of you ?


    The C project github : https://github.com/nicbarker/clay
    My code repo : https://codeberg.org/Frizzus/Lime-Stained-Terracota


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Thu Oct 16 16:00:39 2025
    From Newsgroup: comp.lang.tcl

    * Frizzus <loic.canin@murena.io>
    | % load ./liblst_raylib.so
    | cannot find symbol "Lst_raylib_Init":
    | /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so:
    | undefined symbol: _Lst_raylib_Init

    As Robert pointed out, you need to provide that function in your
    extension module. See
    https://wiki.tcl-lang.org/page/Hello+World+as+a+C+extension
    for an example. You need to adjust the Hello_Init() function to your
    library.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Oct 16 14:33:44 2025
    From Newsgroup: comp.lang.tcl

    At Thu, 16 Oct 2025 16:00:39 +0200 Ralf Fassel <ralfixx@gmx.de> wrote:

    * Frizzus <loic.canin@murena.io>
    | % load ./liblst_raylib.so
    | cannot find symbol "Lst_raylib_Init":
    | /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so:
    | undefined symbol: _Lst_raylib_Init

    As Robert pointed out, you need to provide that function in your
    extension module. See
    https://wiki.tcl-lang.org/page/Hello+World+as+a+C+extension
    for an example. You need to adjust the Hello_Init() function to your library.
    Yes, and it is important that the name match the library name. It is possible to override that with a second argument to the load command, but this is discurraged.

    R'


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Frizzus@loic.canin@murena.io to comp.lang.tcl on Fri Oct 17 15:41:36 2025
    From Newsgroup: comp.lang.tcl

    Le 16/10/2025 à 16:33, Robert Heller a écrit :
    At Thu, 16 Oct 2025 16:00:39 +0200 Ralf Fassel <ralfixx@gmx.de> wrote:


    * Frizzus <loic.canin@murena.io>
    | % load ./liblst_raylib.so
    | cannot find symbol "Lst_raylib_Init":
    | /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so:
    | undefined symbol: _Lst_raylib_Init

    As Robert pointed out, you need to provide that function in your
    extension module. See
    https://wiki.tcl-lang.org/page/Hello+World+as+a+C+extension
    for an example. You need to adjust the Hello_Init() function to your
    library.

    Yes, and it is important that the name match the library name. It is possible
    to override that with a second argument to the load command, but this is discurraged.


    R'




    thanks, the name of the library and the name of the Init function were
    not the same.

    I thought the "DLLEXPORT" symbol on the Init function definition was
    here to define this function as the entry point.

    Is this a common pattern in dynamic library to have the entry function matching the library name ?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Fri Oct 17 15:55:12 2025
    From Newsgroup: comp.lang.tcl

    Am 17.10.2025 um 15:41 schrieb Frizzus:
    Is this a common pattern in dynamic library to have the entry function matching the library name ?

    This is TCL specific.

    The DLLEXPORT instructs the linker to export the symbol, so TCL can
    finde it.

    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon Oct 20 12:20:31 2025
    From Newsgroup: comp.lang.tcl

    * Frizzus <loic.canin@murena.io>
    | Le 16/10/2025 à 16:33, Robert Heller a écrit :
    | > At Thu, 16 Oct 2025 16:00:39 +0200 Ralf Fassel <ralfixx@gmx.de> wrote:
    | >
    | >>
    | >> * Frizzus <loic.canin@murena.io>
    | >> | % load ./liblst_raylib.so
    | >> | cannot find symbol "Lst_raylib_Init":
    | >> | /home/frizzus/Documents/code/Lime-Stained-Terracota/liblst_raylib.so:
    | >> | undefined symbol: _Lst_raylib_Init
    | >>
    | >> As Robert pointed out, you need to provide that function in your
    | >> extension module. See
    | >> https://wiki.tcl-lang.org/page/Hello+World+as+a+C+extension
    | >> for an example. You need to adjust the Hello_Init() function to your
    | >> library.
    | > Yes, and it is important that the name match the library name. It
    | > is possible
    | > to override that with a second argument to the load command, but this is
    | > discurraged.
    | >

    | thanks, the name of the library and the name of the Init function were
    | not the same.

    See the TCL 'load' manpage for details on the initialization function.

    https://www.tcl-lang.org/man/tcl8.6/TclCmd/load.htm

    You may specify a different prefix for the init-function, but even then
    there are some restraints on the name (see manpage for details).

    | I thought the "DLLEXPORT" symbol on the Init function definition was
    | here to define this function as the entry point.

    DLLEXPORT on some systems (notably Windows) has the meaning to 'export'
    this function from the library so it may be called by code from outside
    of the library. On these systems, DLLEXPORT is required for init-style functions, but functions declared as 'export' are not automatically
    called.

    | Is this a common pattern in dynamic library to have the entry function
    | matching the library name ?

    Calling the init-function in the way as described by the 'load' manpage
    is TCL-specific.

    HTH
    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2