oooutlk / tcltk

Rust bindings to Tcl/Tk commands
Apache License 2.0
22 stars 3 forks source link

Bug: Can't compile example: missing clib::Tcl_Eval `tk` #6

Closed felipetesc closed 1 year ago

felipetesc commented 1 year ago

Expected Behavior

To be able to run examples

Current Behavior

I can't compile or run a tk example

Possible Solution

Fix clip missing import : clib::Tcl_Eval

Steps to Reproduce

  1. cargo run --example add_menus
  2. Read ouput

Context (Environment)

Ubuntu 22.04 x86_x64 rustc 1.69.0 (84c898d65 2023-04-16) cargo 1.69.0 (6e9a83356 2023-04-12) tk version = "0.1.5"

Context (Output)

cargo run --example add_menus
   Compiling tk v0.1.5 (/home/ftx10/Desktop/RustTkProject/tcltk/tk)
warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:106:23
    |
106 |         let tcl_obj = unsafe{ clib::Tcl_NewObj() };
    |                       ^^^^^^ unnecessary `unsafe` block
    |
    = note: `#[warn(unused_unsafe)]` on by default

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:155:9
    |
155 |         unsafe{ clib::Tcl_InvalidateStringRep( self.0.as_ptr() ); }
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:235:9
    |
235 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:251:9
    |
251 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:289:20
    |
289 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut value...
    |                    ^^^^^^ unnecessary `unsafe` block
...
312 | int_from_obj!( Tcl_GetIntFromObj     c_int      =>  i8   as_i8    NotI8   ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:301:20
    |
301 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut valu...
    |                    ^^^^^^ unnecessary `unsafe` block
...
312 | int_from_obj!( Tcl_GetIntFromObj     c_int      =>  i8   as_i8    NotI8   ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:289:20
    |
289 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut value...
    |                    ^^^^^^ unnecessary `unsafe` block
...
313 | int_from_obj!( Tcl_GetLongFromObj    c_long     => i16   as_i16   NotI16  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:301:20
    |
301 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut valu...
    |                    ^^^^^^ unnecessary `unsafe` block
...
313 | int_from_obj!( Tcl_GetLongFromObj    c_long     => i16   as_i16   NotI16  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:289:20
    |
289 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut value...
    |                    ^^^^^^ unnecessary `unsafe` block
...
314 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => i32   as_i32   NotI32  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:301:20
    |
301 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut valu...
    |                    ^^^^^^ unnecessary `unsafe` block
...
314 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => i32   as_i32   NotI32  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:289:20
    |
289 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut value...
    |                    ^^^^^^ unnecessary `unsafe` block
...
315 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => i64   as_i64   NotI64  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:301:20
    |
301 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut valu...
    |                    ^^^^^^ unnecessary `unsafe` block
...
315 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => i64   as_i64   NotI64  ...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:289:20
    |
289 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut value...
    |                    ^^^^^^ unnecessary `unsafe` block
...
316 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => isize as_isize NotISize...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:301:20
    |
301 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut valu...
    |                    ^^^^^^ unnecessary `unsafe` block
...
316 | int_from_obj!( Tcl_GetWideIntFromObj c_longlong => isize as_isize NotISize...
    | ---------------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `int_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:325:20
    |
325 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut ...
    |                    ^^^^^^ unnecessary `unsafe` block
...
348 | uint_from_obj!( Tcl_GetIntFromObj     c_int      =>  u8 as_u8  NotU8  );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:337:20
    |
337 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut...
    |                    ^^^^^^ unnecessary `unsafe` block
...
348 | uint_from_obj!( Tcl_GetIntFromObj     c_int      =>  u8 as_u8  NotU8  );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:325:20
    |
325 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut ...
    |                    ^^^^^^ unnecessary `unsafe` block
...
349 | uint_from_obj!( Tcl_GetLongFromObj    c_long     => u16 as_u16 NotU16 );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:337:20
    |
337 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut...
    |                    ^^^^^^ unnecessary `unsafe` block
...
349 | uint_from_obj!( Tcl_GetLongFromObj    c_long     => u16 as_u16 NotU16 );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:325:20
    |
325 |                 if unsafe{ clib::$tcl_api( null_mut(), obj.as_ptr(), &mut ...
    |                    ^^^^^^ unnecessary `unsafe` block
...
350 | uint_from_obj!( Tcl_GetWideIntFromObj c_longlong => u32 as_u32 NotU32 );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:337:20
    |
337 |                 if unsafe{ clib::$tcl_api( null_mut(), self.as_ptr(), &mut...
    |                    ^^^^^^ unnecessary `unsafe` block
...
350 | uint_from_obj!( Tcl_GetWideIntFromObj c_longlong => u32 as_u32 NotU32 );
    | ----------------------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `uint_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:402:17
    |
402 |                 unsafe {
    |                 ^^^^^^ unnecessary `unsafe` block
...
425 | float_from_obj!( f32, NotF32, as_f32 );
    | -------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `float_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:414:17
    |
414 |                 unsafe {
    |                 ^^^^^^ unnecessary `unsafe` block
...
425 | float_from_obj!( f32, NotF32, as_f32 );
    | -------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `float_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:402:17
    |
402 |                 unsafe {
    |                 ^^^^^^ unnecessary `unsafe` block
...
426 | float_from_obj!( f64, NotF64, as_f64 );
    | -------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `float_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:414:17
    |
414 |                 unsafe {
    |                 ^^^^^^ unnecessary `unsafe` block
...
426 | float_from_obj!( f64, NotF64, as_f64 );
    | -------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `float_from_obj` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:511:20
    |
511 | ...   let list = unsafe{ clib::Tcl_NewListObj( v.len() as c_int, v.as_p...
    |                  ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/obj.rs:523:20
    |
523 | ...   let list = unsafe{ clib::Tcl_NewListObj( v.len() as c_int, v.as_p...
    |                  ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ext.rs:140:9
    |
140 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ext.rs:256:24
    |
256 |     let mut type_ptr = unsafe{ clib::Tcl_GetObjType( type_id.as_ptr() )};
    |                        ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ext.rs:259:20
    |
259 |         type_ptr = unsafe{ clib::Tcl_GetObjType( type_id.as_ptr() )};
    |                    ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ext.rs:302:9
    |
302 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/ser.rs:71:17
   |
71 |         let s = unsafe{ clib::Tcl_Alloc( len + 1 )};
   |                 ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/ser.rs:84:9
   |
84 |         unsafe{ Tcl_DStringStartSublist( self.as_mut_ptr() ); }
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/ser.rs:93:9
   |
93 |         unsafe{ Tcl_DStringEndSublist( self.as_mut_ptr() ); }
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/ser.rs:99:9
   |
99 |         unsafe {
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ser.rs:108:9
    |
108 | ...   unsafe{ Tcl_DStringAppendElement( self.as_mut_ptr(), cstring.as_p...
    |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/ser.rs:114:9
    |
114 | ...   unsafe{ Tcl_DStringAppendElement( self.as_mut_ptr(),  rhs.0.strin...
    |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/dict.rs:36:23
   |
36 |         let tcl_obj = unsafe{ clib::Tcl_NewDictObj() };
   |                       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/dict.rs:64:9
   |
64 |         unsafe {
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/dict.rs:107:13
    |
107 |             unsafe {
    |             ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/dict.rs:148:13
    |
148 |             unsafe {
    |             ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/dict.rs:179:9
    |
179 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/dict.rs:238:35
    |
238 |             Some( mut search ) => unsafe {
    |                                   ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/list.rs:24:20
   |
24 |         let list = unsafe{ clib::Tcl_NewListObj( objc, objv )};
   |                    ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/list.rs:39:9
   |
39 |         unsafe{ clib::Tcl_SetListObj( self.as_ptr(), objc, objv ); }
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/list.rs:56:9
   |
56 | ...   unsafe{ clib::Tcl_ListObjAppendList( null_mut(), self.as_ptr(), to...
   |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/list.rs:73:9
   |
73 | ...   unsafe{ clib::Tcl_ListObjAppendElement( null_mut(), self.as_ptr(),...
   |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> tcl/src/list.rs:95:13
   |
95 | ...   unsafe{ clib::Tcl_ListObjGetElements( null_mut(), self.as_ptr(), &...
   |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/list.rs:120:9
    |
120 | ...   unsafe{ clib::Tcl_ListObjLength( null_mut(), self.as_ptr(), &mut ...
    |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/list.rs:139:9
    |
139 | ...   unsafe{ clib::Tcl_ListObjIndex( null_mut(), self.as_ptr(), index,...
    |       ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/list.rs:175:22
    |
175 | ...   let result = unsafe{ clib::Tcl_ListObjReplace( null_mut(), self.a...
    |                    ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
   --> tcl/src/lib.rs:250:9
    |
250 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block

warning: `tcl` (lib) generated 51 warnings
error[E0425]: cannot find function, tuple struct or tuple variant `Tcl_Eval` in crate `clib`
   --> tk/src/lib.rs:424:34
    |
424 | ...   if unsafe{ clib::Tcl_Eval( tcl_interp, script )} == clib::TCL_OK ...
    |                        ^^^^^^^^ not found in `clib`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `tk` due to previous error
rdbende commented 1 year ago

You also need to add tcl crate as a dependency. Then it should work.

[dependencies]
tcl = "0.1.5"
tk = "0.1.5"
felipetesc commented 1 year ago
  1. cargo run --example add_menus

It happened while executing a tk example inside tk examples folder itself. All imports are ok inside the tcltk folder

rdbende commented 1 year ago

Oh, I see. When I first started a project with tcltk in Rust I got the same error, but adding tcl as a dependency solved it. The examples work just fine.

felipetesc commented 1 year ago

Oh, I see. When I first started a project with tcltk in Rust I got the same error, but adding tcl as a dependency solved it. The examples work just fine.

Did you clone the repository, or have you created a new proj ? (So, I can test it again.)

rdbende commented 1 year ago

I created a new project with cargo.

oooutlk commented 1 year ago

Would you please show me clib’s bindings.rs generated in $OUT directory?

felipetesc commented 1 year ago

Would you please show me clib’s bindings.rs generated in $OUT directory?

Here you go:

macro_rules! t {
    () => {
        eprintln!("The crate clib failed in probing tcl library for the crate tcl, any invocation of Tcl's C API will abort the program.");
        std::process::abort();
    }
}
pub type ClientData = *mut ::std::os::raw::c_void;
pub fn Tcl_Alloc(size: ::std::os::raw::c_uint) -> *mut ::std::os::raw::c_char {t!();}
pub type Tcl_AppInitProc =
    ::std::option::Option<unsafe extern "C" fn(interp: *mut Tcl_Interp) -> ::std::os::raw::c_int>;
pub const TCL_APPEND_VALUE: u32 = 4;
pub type Tcl_CmdDeleteProc = ::std::option::Option<unsafe extern "C" fn(clientData: ClientData)>;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_Command_ {
    _unused: [u8; 0],
}
pub type Tcl_Command = *mut Tcl_Command_;
pub fn Tcl_CreateInterp() -> *mut Tcl_Interp {t!();}
pub fn Tcl_CreateObjCommand(
    interp: *mut Tcl_Interp,
    cmdName: *const ::std::os::raw::c_char,
    proc_: Tcl_ObjCmdProc,
    clientData: ClientData,
    deleteProc: Tcl_CmdDeleteProc,
) -> Tcl_Command {t!();}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_DString {
    pub string: *mut ::std::os::raw::c_char,
    pub length: ::std::os::raw::c_int,
    pub spaceAvl: ::std::os::raw::c_int,
    pub staticSpace: [::std::os::raw::c_char; 200usize],
}
pub fn Tcl_DStringInit(dsPtr: *mut Tcl_DString) {t!();}
pub fn Tcl_DStringAppendElement(
    dsPtr: *mut Tcl_DString,
    element: *const ::std::os::raw::c_char,
) -> *mut ::std::os::raw::c_char {t!();}
pub fn Tcl_DStringStartSublist(dsPtr: *mut Tcl_DString) {t!();}
pub fn Tcl_DStringEndSublist(dsPtr: *mut Tcl_DString) {t!();}
pub fn Tcl_DStringFree(dsPtr: *mut Tcl_DString) {t!();}
pub fn Tcl_DeleteInterp(interp: *mut Tcl_Interp) {t!();}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_Dict_ {
    _unused: [u8; 0],
}
pub type Tcl_Dict = *mut Tcl_Dict_;
pub fn Tcl_DictObjFirst(
    interp: *mut Tcl_Interp,
    dictPtr: *mut Tcl_Obj,
    searchPtr: *mut Tcl_DictSearch,
    keyPtrPtr: *mut *mut Tcl_Obj,
    valuePtrPtr: *mut *mut Tcl_Obj,
    donePtr: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_DictObjGet(
    interp: *mut Tcl_Interp,
    dictPtr: *mut Tcl_Obj,
    keyPtr: *mut Tcl_Obj,
    valuePtrPtr: *mut *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_DictObjNext(
    searchPtr: *mut Tcl_DictSearch,
    keyPtrPtr: *mut *mut Tcl_Obj,
    valuePtrPtr: *mut *mut Tcl_Obj,
    donePtr: *mut ::std::os::raw::c_int,
) {t!();}
pub fn Tcl_DictObjPut(
    interp: *mut Tcl_Interp,
    dictPtr: *mut Tcl_Obj,
    keyPtr: *mut Tcl_Obj,
    valuePtr: *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_DictObjRemove(
    interp: *mut Tcl_Interp,
    dictPtr: *mut Tcl_Obj,
    keyPtr: *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_DictObjSize(
    interp: *mut Tcl_Interp,
    dictPtr: *mut Tcl_Obj,
    sizePtr: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_DictSearch {
    pub next: *mut ::std::os::raw::c_void,
    pub epoch: ::std::os::raw::c_int,
    pub dictionaryPtr: Tcl_Dict,
}
pub fn Tcl_DoOneEvent(flags: ::std::os::raw::c_int) -> ::std::os::raw::c_int {t!();}
pub type Tcl_DupInternalRepProc =
    ::std::option::Option<unsafe extern "C" fn(srcPtr: *mut Tcl_Obj, dupPtr: *mut Tcl_Obj)>;
pub const TCL_ERROR: u32 = 1;
pub fn Tcl_EvalObjEx(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    flags: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_FindExecutable(argv0: *const ::std::os::raw::c_char) {t!();}
pub type Tcl_FreeInternalRepProc =
    ::std::option::Option<unsafe extern "C" fn(objPtr: *mut Tcl_Obj)>;
pub fn Tcl_GetBooleanFromObj(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    intPtr: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_GetDoubleFromObj(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    doublePtr: *mut f64,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_GetIntFromObj(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    intPtr: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_GetLongFromObj(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    longPtr: *mut ::std::os::raw::c_long,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_GetNameOfExecutable() -> *const ::std::os::raw::c_char {t!();}
pub fn Tcl_GetObjResult(interp: *mut Tcl_Interp) -> *mut Tcl_Obj {t!();}
pub fn Tcl_GetObjType(typeName: *const ::std::os::raw::c_char) -> *const Tcl_ObjType {t!();}
pub fn Tcl_GetReturnOptions(
    interp: *mut Tcl_Interp,
    result: ::std::os::raw::c_int,
) -> *mut Tcl_Obj {t!();}
pub fn Tcl_GetStringFromObj(
    objPtr: *mut Tcl_Obj,
    lengthPtr: *mut ::std::os::raw::c_int,
) -> *mut ::std::os::raw::c_char {t!();}
pub fn Tcl_GetWideIntFromObj(
    interp: *mut Tcl_Interp,
    objPtr: *mut Tcl_Obj,
    widePtr: *mut Tcl_WideInt,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_Init(interp: *mut Tcl_Interp) -> ::std::os::raw::c_int {t!();}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_Interp {
    pub resultDontUse: *mut ::std::os::raw::c_char,
    pub freeProcDontUse:
        ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_char)>,
    pub errorLineDontUse: ::std::os::raw::c_int,
}
pub fn Tcl_InvalidateStringRep(objPtr: *mut Tcl_Obj) {t!();}
pub const TCL_LEAVE_ERR_MSG: u32 = 512;
pub const TCL_LIST_ELEMENT: u32 = 8;
pub fn Tcl_ListObjAppendElement(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    objPtr: *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_ListObjAppendList(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    elemListPtr: *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_ListObjGetElements(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    objcPtr: *mut ::std::os::raw::c_int,
    objvPtr: *mut *mut *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_ListObjIndex(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    index: ::std::os::raw::c_int,
    objPtrPtr: *mut *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_ListObjLength(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    lengthPtr: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_ListObjReplace(
    interp: *mut Tcl_Interp,
    listPtr: *mut Tcl_Obj,
    first: ::std::os::raw::c_int,
    count: ::std::os::raw::c_int,
    objc: ::std::os::raw::c_int,
    objv: *const *mut Tcl_Obj,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_NewDictObj() -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewDoubleObj(doubleValue: f64) -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewIntObj(intValue: ::std::os::raw::c_int) -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewListObj(objc: ::std::os::raw::c_int, objv: *const *mut Tcl_Obj) -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewObj() -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewStringObj(
    bytes: *const ::std::os::raw::c_char,
    length: ::std::os::raw::c_int,
) -> *mut Tcl_Obj {t!();}
pub fn Tcl_NewWideIntObj(wideValue: Tcl_WideInt) -> *mut Tcl_Obj {t!();}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Tcl_Obj {
    pub refCount: ::std::os::raw::c_int,
    pub bytes: *mut ::std::os::raw::c_char,
    pub length: ::std::os::raw::c_int,
    pub typePtr: *const Tcl_ObjType,
    pub internalRep: Tcl_Obj__bindgen_ty_1,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union Tcl_Obj__bindgen_ty_1 {
    pub longValue: ::std::os::raw::c_long,
    pub doubleValue: f64,
    pub otherValuePtr: *mut ::std::os::raw::c_void,
    pub wideValue: Tcl_WideInt,
    pub twoPtrValue: Tcl_Obj__bindgen_ty_1__bindgen_ty_1,
    pub ptrAndLongRep: Tcl_Obj__bindgen_ty_1__bindgen_ty_2,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_Obj__bindgen_ty_1__bindgen_ty_1 {
    pub ptr1: *mut ::std::os::raw::c_void,
    pub ptr2: *mut ::std::os::raw::c_void,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_Obj__bindgen_ty_1__bindgen_ty_2 {
    pub ptr: *mut ::std::os::raw::c_void,
    pub value: ::std::os::raw::c_ulong,
}
pub fn Tcl_ObjGetVar2(
    interp: *mut Tcl_Interp,
    part1Ptr: *mut Tcl_Obj,
    part2Ptr: *mut Tcl_Obj,
    flags: ::std::os::raw::c_int,
) -> *mut Tcl_Obj {t!();}
pub fn Tcl_ObjSetVar2(
    interp: *mut Tcl_Interp,
    part1Ptr: *mut Tcl_Obj,
    part2Ptr: *mut Tcl_Obj,
    newValuePtr: *mut Tcl_Obj,
    flags: ::std::os::raw::c_int,
) -> *mut Tcl_Obj {t!();}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Tcl_ObjType {
    pub name: *const ::std::os::raw::c_char,
    pub freeIntRepProc: Tcl_FreeInternalRepProc,
    pub dupIntRepProc: Tcl_DupInternalRepProc,
    pub updateStringProc: Tcl_UpdateStringProc,
    pub setFromAnyProc: Tcl_SetFromAnyProc,
}
pub const TCL_OK: u32 = 0;
pub fn Tcl_Panic(format: *const ::std::os::raw::c_char) -> ! {t!();}
pub fn Tcl_RegisterObjType(typePtr: *const Tcl_ObjType) {t!();}
pub type Tcl_SetFromAnyProc = ::std::option::Option<
    unsafe extern "C" fn(interp: *mut Tcl_Interp, objPtr: *mut Tcl_Obj) -> ::std::os::raw::c_int,
>;
pub fn Tcl_SetListObj(
    objPtr: *mut Tcl_Obj,
    objc: ::std::os::raw::c_int,
    objv: *const *mut Tcl_Obj,
) {t!();}
pub fn Tcl_SetObjErrorCode(interp: *mut Tcl_Interp, errorObjPtr: *mut Tcl_Obj) {t!();}
pub fn Tcl_SetObjResult(interp: *mut Tcl_Interp, resultObjPtr: *mut Tcl_Obj) {t!();}
pub type Tcl_ObjCmdProc = ::std::option::Option<
    unsafe extern "C" fn(
        clientData: ClientData,
        interp: *mut Tcl_Interp,
        objc: ::std::os::raw::c_int,
        objv: *const *mut Tcl_Obj,
    ) -> ::std::os::raw::c_int,
>;
pub fn Tcl_UnsetVar(
    interp: *mut Tcl_Interp,
    varName: *const ::std::os::raw::c_char,
    flags: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub fn Tcl_UnsetVar2(
    interp: *mut Tcl_Interp,
    part1: *const ::std::os::raw::c_char,
    part2: *const ::std::os::raw::c_char,
    flags: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {t!();}
pub type Tcl_UpdateStringProc = ::std::option::Option<unsafe extern "C" fn(objPtr: *mut Tcl_Obj)>;
pub type Tcl_WideInt = ::std::os::raw::c_longlong;
pub fn Tcl_WrongNumArgs(
    interp: *mut Tcl_Interp,
    objc: ::std::os::raw::c_int,
    objv: *const *mut Tcl_Obj,
    message: *const ::std::os::raw::c_char,
) {t!();}
pub fn TclFreeObj(objPtr: *mut Tcl_Obj) {t!();}

So, bindings is missing Tcl_Eval

felipetesc commented 1 year ago

Oh, I see. When I first started a project with tcltk in Rust I got the same error, but adding tcl as a dependency solved it. The examples work just fine.

What version did you use, rustc, and what OS ? Did you clone the repository, because that's what I did.

felipetesc commented 1 year ago

Its working on Windows 11, I checked bindings.rs on Windows and the method Tcl_Eval is there, but the problem still persists on Ubuntu 22.04 since its missing the method. I'll copy and paste the function on ubuntu and see what happens.

rdbende commented 1 year ago

System: Fedora Workstation 38

[dependencies]
tcl = "0.1.5"
tk = "0.1.5"

Created a new project using cargo new demo_tcltk, added tcl and tk crates using cargo add tcl tk, used cargo run to run.

src/main.rs:

use tk::cmd::*;
use tk::*;

fn main() -> TkResult<()> {
    let tk = make_tk!()?;
    let root = tk.root();
    root.add_ttk_label(-text("Foobar"))?.grid(())?;
    root.set_wm_geometry(TkGeometry{ w: 400, h: 300, x: 200, y: 100 })?;

    Ok(main_loop())
}
felipetesc commented 1 year ago

After adding at the bottom of bindings.rs the code :

pub fn Tcl_Eval(
    interp: *mut Tcl_Interp,
    script: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int {t!();}

I could compile the example.

felipetesc commented 1 year ago

System: Fedora Workstation 38

[dependencies]
tcl = "0.1.5"
tk = "0.1.5"

Created a new project using cargo new demo_tcltk, added tcl and tk crates using cargo add tcl tk, used cargo run to run.

src/main.rs:

use tk::cmd::*;
use tk::*;

fn main() -> TkResult<()> {
    let tk = make_tk!()?;
    let root = tk.root();
    root.add_ttk_label(-text("Foobar"))?.grid(())?;
    root.set_wm_geometry(TkGeometry{ w: 400, h: 300, x: 200, y: 100 })?;

    Ok(main_loop())
}

Followed exactly the same and I got:

error: /home/ftx10/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tk-0.1.5/src/lib.rs:424: cannot find function, tuple struct or tuple variant `Tcl_Eval` in crate `clib`
error: /home/ftx10/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tk-0.1.5/src/lib.rs:424: Errors occurred in /home/ftx10/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tk-0.1.5/src/lib.rs from external crate
error: /home/ftx10/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tk-0.1.5/src/lib.rs:424: Macro text:                 if unsafe{ clib::Tcl_Eval( tcl_interp, script )} == clib::TCL_OK as c_int {
error: /home/ftx10/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tk-0.1.5/src/lib.rs:424: not found in `clib`
error: could not compile `tk` (lib) due to 2 previous errors
felipetesc commented 1 year ago

Fixed. I'm feeling stupid actually. The problem was related to the fact Ubuntu divides its libraries into dev packages and the runtime. So, it could not find probably the c include files. For people which may find the same problem install tk, tcl, tk-dev, tcl-dev, libclang and libclang-dev.

rdbende commented 1 year ago

Oh yeah. Those development packages were already installed for me, because I also build Tk extensions in C. I didn't even notice that they were necessary.

oooutlk commented 1 year ago

Yes, on Debian/Ubuntu "-dev" packages are required. By the way, the binding.rs containing t!() is a quick fix for forcing docs.rs to generate document pages without the need of installing native tcl/tk packages on their docker machines. If you see it on your disk, that indicates the failure of clib.