Page 1 of 1

[Done] Can not use a structure in an Import

Posted: Fri Jul 18, 2025 9:59 am
by infratec
Hi,

I need to import a global variable from an external statically linked library.

In windows and linux this works without problems. In macOS it fails with a compiler error.

Example:

Code: Select all

Structure pjsip_cfg_t Align #PB_Structure_AlignC
  allow_port_in_fromto_hdr.pj_bool_t
  accept_replace_in_early_state.pj_bool_t
  allow_tx_hash_in_uri.pj_bool_t
  disable_rport.pj_bool_t
  disable_tcp_switch.pj_bool_t
  disable_tls_switch.pj_bool_t
  follow_early_media_fork.pj_bool_t
  req_has_via_alias.pj_bool_t
  resolve_hostname_to_get_interface.pj_bool_t
  disable_secure_dlg_check.pj_bool_t
  use_compact_form.pj_bool_t
  accept_multiple_sdp_answers.pj_bool_t
  keep_inv_after_tsx_timeout.pj_bool_t
EndStructure

ImportC #LibPJProjectFile
    pjsip_sip_cfg_var.pjsip_cfg_t
EndImport
results in a 'PureBasic - Assembler error':
error: unknown type name 's_pjsip_cfg_t'
100 | extern s_pjsip_cfg_t v_pjsip_sip_cfg_var asm("_pjsip_sip_cfg_var");
| ^
1 error generated.



Ugly bugfix for macOS:

Code: Select all

ImportC #LibPJProjectFile
  ; BugFix für macOS -> kann keine lokale Struktur hinter exportierter Variable
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    pjsip_sip_cfg_var
  CompilerElse
    pjsip_sip_cfg_var.pjsip_cfg_t
  CompilerEndIf
EndImport

; BugFix für macOS -> kann keine lokale Struktur hinter exportierter Variable
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  Global *pjsip_sip_cfg_var.pjsip_cfg_t
  *pjsip_sip_cfg_var = @pjsip_sip_cfg_var
CompilerEndIf
I tried to solve the different variable names with a Macro, but it is not allowed to use a variabe name as a Macro.
So I also need a CompilerIf in the code where the variable is used. (But I hope this will be solved in future :wink: )

I can not provide a code which reproduce the error. Sorry.

Re: Can not use a structure in an Import

Posted: Fri Sep 19, 2025 12:41 pm
by Fred
Fixed.

Re: [Done] Can not use a structure in an Import

Posted: Fri Sep 19, 2025 9:40 pm
by Piero
infratec wrote: Fri Jul 18, 2025 9:59 amI tried to solve the different variable names with a Macro, but it is not allowed to use a variabe name as a Macro.
Did you see this?

Code: Select all

Macro myMac(a,b)
  Global *#a#.#b
  *#a = @#a
EndMacro

myMac(pjsip_sip_cfg_var,pjsip_cfg_t)

Re: [Done] Can not use a structure in an Import

Posted: Fri Sep 19, 2025 9:50 pm
by infratec
That's not what I meant.

I meant something like this, to avoid the additonal CompilerIf for macOS

Code: Select all

Macro pjsip_sip_cfg_var
  *pjsip_sip_cfg_var
EndMacro
But the problem is solved now :mrgreen:

Re: [Done] Can not use a structure in an Import

Posted: Fri Sep 19, 2025 10:44 pm
by Piero

Code: Select all

Macro pjsip_sip_cfg_va
   *pjsip_sip_cfg_var
EndMacro
:mrgreen:
Edit: just a joke to """almost use a variable"""