[Done] Can not use a structure in an Import

Post bugreports for the Mac OSX version here
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

[Done] Can not use a structure in an Import

Post 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.
Fred
Administrator
Administrator
Posts: 18349
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Can not use a structure in an Import

Post by Fred »

Fixed.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

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

Post 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)
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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:
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

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

Post 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"""
Post Reply